@insforge/instabox-sdk 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +227 -2
- package/dist/index.cjs +700 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +466 -0
- package/dist/index.d.ts +466 -0
- package/dist/index.js +677 -0
- package/dist/index.js.map +1 -0
- package/package.json +65 -4
- package/skills/instabox/SKILL.md +116 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,466 @@
|
|
|
1
|
+
/** Fields of the instabox API error envelope `{ error: { code, message, requestId, retryable, operationId } }`. */
|
|
2
|
+
interface InstaboxErrorInit {
|
|
3
|
+
status?: number;
|
|
4
|
+
code?: string;
|
|
5
|
+
requestId?: string;
|
|
6
|
+
retryable?: boolean;
|
|
7
|
+
operationId?: string | null;
|
|
8
|
+
cause?: unknown;
|
|
9
|
+
}
|
|
10
|
+
/** Base class for every error this SDK throws. */
|
|
11
|
+
declare class InstaboxError extends Error {
|
|
12
|
+
/** HTTP status, or 0 when the error did not come from an HTTP response (for example a failed operation). */
|
|
13
|
+
readonly status: number;
|
|
14
|
+
/** Machine-readable code from the API, e.g. `not_found`, `operation_conflict`. */
|
|
15
|
+
readonly code: string;
|
|
16
|
+
readonly requestId?: string;
|
|
17
|
+
readonly retryable: boolean;
|
|
18
|
+
/** For `operation_conflict` the active operation, for a failed operation its ID. */
|
|
19
|
+
readonly operationId?: string | null;
|
|
20
|
+
constructor(message: string, init?: InstaboxErrorInit);
|
|
21
|
+
}
|
|
22
|
+
/** 401 / 403: missing, invalid or revoked API key, or not allowed. */
|
|
23
|
+
declare class InstaboxAuthError extends InstaboxError {
|
|
24
|
+
}
|
|
25
|
+
/** 429 `quota_exceeded`: an account limit was reached (for example the machine limit). */
|
|
26
|
+
declare class InstaboxQuotaError extends InstaboxError {
|
|
27
|
+
}
|
|
28
|
+
/** A request or an operation did not finish in time. */
|
|
29
|
+
declare class InstaboxTimeoutError extends InstaboxError {
|
|
30
|
+
}
|
|
31
|
+
/** Result of a finished command. */
|
|
32
|
+
interface CommandResult {
|
|
33
|
+
stdout: string;
|
|
34
|
+
stderr: string;
|
|
35
|
+
exitCode: number;
|
|
36
|
+
timedOut: boolean;
|
|
37
|
+
truncated: boolean;
|
|
38
|
+
/** Error text reported by the server, if any. */
|
|
39
|
+
error?: string;
|
|
40
|
+
}
|
|
41
|
+
/** A command exited with a non-zero code. Carries the full result. */
|
|
42
|
+
declare class CommandExitError extends InstaboxError implements CommandResult {
|
|
43
|
+
readonly stdout: string;
|
|
44
|
+
readonly stderr: string;
|
|
45
|
+
readonly exitCode: number;
|
|
46
|
+
readonly timedOut: boolean;
|
|
47
|
+
readonly truncated: boolean;
|
|
48
|
+
readonly error?: string;
|
|
49
|
+
constructor(result: CommandResult);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
type MachineState = 'creating' | 'starting' | 'running' | 'stopping' | 'stopped' | 'suspending' | 'suspended' | 'resuming' | 'deleting' | 'deleted' | 'error';
|
|
53
|
+
interface ApiError {
|
|
54
|
+
code: string;
|
|
55
|
+
message: string;
|
|
56
|
+
requestId: string;
|
|
57
|
+
retryable: boolean;
|
|
58
|
+
operationId: string | null;
|
|
59
|
+
}
|
|
60
|
+
interface MachineSpec {
|
|
61
|
+
vcpus: number;
|
|
62
|
+
memMiB: number;
|
|
63
|
+
persistentDiskGiB: number;
|
|
64
|
+
rootDiskGiB?: number;
|
|
65
|
+
}
|
|
66
|
+
interface TemplateRef {
|
|
67
|
+
id: string;
|
|
68
|
+
version: string;
|
|
69
|
+
digest: string;
|
|
70
|
+
}
|
|
71
|
+
interface Machine {
|
|
72
|
+
id: string;
|
|
73
|
+
name: string;
|
|
74
|
+
desiredState: MachineState;
|
|
75
|
+
state: MachineState;
|
|
76
|
+
revision: number;
|
|
77
|
+
operationId: string | null;
|
|
78
|
+
template: TemplateRef;
|
|
79
|
+
snapshot?: {
|
|
80
|
+
id: string;
|
|
81
|
+
};
|
|
82
|
+
forkedFrom?: {
|
|
83
|
+
machineId: string;
|
|
84
|
+
snapshotSeq: number;
|
|
85
|
+
};
|
|
86
|
+
spec: MachineSpec;
|
|
87
|
+
storage: {
|
|
88
|
+
sizeGiB: number;
|
|
89
|
+
mountPath: string;
|
|
90
|
+
persistent: boolean;
|
|
91
|
+
synced: boolean;
|
|
92
|
+
snapshotSeq?: number;
|
|
93
|
+
};
|
|
94
|
+
runtime: {
|
|
95
|
+
ready: boolean;
|
|
96
|
+
processesPreserved?: boolean;
|
|
97
|
+
};
|
|
98
|
+
lastError?: ApiError;
|
|
99
|
+
/** When the server pauses or deletes the machine (see `onTimeout`); null for no timeout. */
|
|
100
|
+
timeoutAt?: string | null;
|
|
101
|
+
archiveAt?: string | null;
|
|
102
|
+
onTimeout?: OnTimeout;
|
|
103
|
+
/** String labels, stored by the server. */
|
|
104
|
+
metadata?: Record<string, string>;
|
|
105
|
+
createdAt: string;
|
|
106
|
+
updatedAt: string;
|
|
107
|
+
}
|
|
108
|
+
/** What happens at `timeoutAt`: `pause` suspends the machine, `kill` deletes it. */
|
|
109
|
+
type OnTimeout = 'pause' | 'kill';
|
|
110
|
+
interface MachineList {
|
|
111
|
+
machines: Machine[];
|
|
112
|
+
nextCursor: string | null;
|
|
113
|
+
}
|
|
114
|
+
interface Operation {
|
|
115
|
+
id: string;
|
|
116
|
+
machineId: string;
|
|
117
|
+
type: 'create' | 'start' | 'stop' | 'suspend' | 'resume' | 'delete' | 'fork';
|
|
118
|
+
state: 'queued' | 'running' | 'succeeded' | 'failed';
|
|
119
|
+
phase?: string;
|
|
120
|
+
error: ApiError | null;
|
|
121
|
+
createdAt: string;
|
|
122
|
+
updatedAt: string;
|
|
123
|
+
machine?: Machine;
|
|
124
|
+
}
|
|
125
|
+
interface Snapshot {
|
|
126
|
+
id: string;
|
|
127
|
+
name: string;
|
|
128
|
+
description?: string;
|
|
129
|
+
sourceMachineId: string;
|
|
130
|
+
sourceSnapshotSeq: number;
|
|
131
|
+
template: TemplateRef;
|
|
132
|
+
rootSizeBytes: number;
|
|
133
|
+
dataSizeBytes?: number;
|
|
134
|
+
exclusiveBytes?: number;
|
|
135
|
+
defaultSpec?: MachineSpec;
|
|
136
|
+
createdAt: string;
|
|
137
|
+
}
|
|
138
|
+
interface Template {
|
|
139
|
+
id: string;
|
|
140
|
+
version: string;
|
|
141
|
+
digest: string;
|
|
142
|
+
arch: string;
|
|
143
|
+
defaultSpec: MachineSpec;
|
|
144
|
+
}
|
|
145
|
+
interface SnapshotList {
|
|
146
|
+
snapshots: Snapshot[];
|
|
147
|
+
}
|
|
148
|
+
interface HostTrust {
|
|
149
|
+
type: 'ca';
|
|
150
|
+
publicKey: string;
|
|
151
|
+
principals: string[];
|
|
152
|
+
}
|
|
153
|
+
interface Connection {
|
|
154
|
+
id: string;
|
|
155
|
+
machineId: string;
|
|
156
|
+
transport: 'ssh';
|
|
157
|
+
host: string;
|
|
158
|
+
port: number;
|
|
159
|
+
username: string;
|
|
160
|
+
certificate: string;
|
|
161
|
+
expiresAt: string;
|
|
162
|
+
hostTrust: HostTrust;
|
|
163
|
+
}
|
|
164
|
+
/** Response of `POST /v1/machines/{id}/exec`. */
|
|
165
|
+
interface ExecResponse {
|
|
166
|
+
stdout: string;
|
|
167
|
+
stderr: string;
|
|
168
|
+
exitCode: number;
|
|
169
|
+
timedOut: boolean;
|
|
170
|
+
truncated: boolean;
|
|
171
|
+
error?: string;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
declare const DEFAULT_API_URL = "https://api.box.instacloud.com";
|
|
175
|
+
/** Options shared by every call that talks to the API. */
|
|
176
|
+
interface ConnectionOptions {
|
|
177
|
+
/** API key from the instabox dashboard's API Keys page. Default: env `INSTABOX_API_KEY`. */
|
|
178
|
+
apiKey?: string;
|
|
179
|
+
/** API base URL. Default: env `INSTABOX_API_URL`, else `https://api.box.instacloud.com`. */
|
|
180
|
+
apiUrl?: string;
|
|
181
|
+
/** Timeout of a single HTTP request in ms. Default 60 000; exec defaults to its command timeout plus 30 000. */
|
|
182
|
+
requestTimeoutMs?: number;
|
|
183
|
+
/** Max time to wait for a lifecycle operation (create, pause, resume, fork, kill) in ms. Default 600 000. */
|
|
184
|
+
operationTimeoutMs?: number;
|
|
185
|
+
/** Custom fetch implementation (tests, proxies). Default: global `fetch`. */
|
|
186
|
+
fetch?: typeof fetch;
|
|
187
|
+
/** Advanced: first delay of operation polling in ms (grows 1.5x to 1 s). Default 250. */
|
|
188
|
+
pollIntervalMs?: number;
|
|
189
|
+
/** Advanced: first delay between retries in ms. Default 250. */
|
|
190
|
+
retryDelayMs?: number;
|
|
191
|
+
}
|
|
192
|
+
interface RequestOptions {
|
|
193
|
+
timeoutMs?: number;
|
|
194
|
+
body?: unknown;
|
|
195
|
+
query?: Record<string, string | number | string[] | undefined>;
|
|
196
|
+
/** Retry on 502/503/504 and network errors. Default: true for GET and for requests carrying an Idempotency-Key. */
|
|
197
|
+
retry?: boolean;
|
|
198
|
+
/** Send an Idempotency-Key. Default: true for every method other than GET/HEAD. */
|
|
199
|
+
idempotent?: boolean;
|
|
200
|
+
}
|
|
201
|
+
declare class HttpClient {
|
|
202
|
+
readonly apiUrl: string;
|
|
203
|
+
readonly operationTimeoutMs: number;
|
|
204
|
+
private readonly apiKey;
|
|
205
|
+
private readonly requestTimeoutMs?;
|
|
206
|
+
private readonly fetchImpl;
|
|
207
|
+
private readonly pollIntervalMs;
|
|
208
|
+
private readonly retryDelayMs;
|
|
209
|
+
constructor(opts?: ConnectionOptions);
|
|
210
|
+
request<T>(method: string, path: string, opts?: RequestOptions): Promise<T>;
|
|
211
|
+
/** Performs the request with retries; returns a 2xx response or throws an InstaboxError. */
|
|
212
|
+
send(method: string, path: string, opts?: RequestOptions): Promise<Response>;
|
|
213
|
+
private backoff;
|
|
214
|
+
/** Polls an operation until it is `succeeded` (returns it) or `failed` (throws). */
|
|
215
|
+
waitForOperation(op: Operation, timeoutMs?: number): Promise<Operation>;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
interface CommandOptions {
|
|
219
|
+
/** Working directory. Default: the server's default (HOME, `/data/home`). */
|
|
220
|
+
cwd?: string;
|
|
221
|
+
/** Extra environment variables, merged over the sandbox-level `envs` from `Sandbox.create`. */
|
|
222
|
+
envs?: Record<string, string>;
|
|
223
|
+
/** Command timeout in ms (sent as whole seconds). Default: the server's default. */
|
|
224
|
+
timeoutMs?: number;
|
|
225
|
+
/** Text sent to the command's standard input. */
|
|
226
|
+
stdin?: string;
|
|
227
|
+
/**
|
|
228
|
+
* Called with stdout once the command finished. Output is not streamed yet:
|
|
229
|
+
* the callback receives the whole stdout in one call.
|
|
230
|
+
*/
|
|
231
|
+
onStdout?: (data: string) => void | Promise<void>;
|
|
232
|
+
/** Like `onStdout`, for stderr. */
|
|
233
|
+
onStderr?: (data: string) => void | Promise<void>;
|
|
234
|
+
/** Start the command detached (nohup) and return right away with its PID. */
|
|
235
|
+
background?: boolean;
|
|
236
|
+
}
|
|
237
|
+
/** A command started with `background: true`. */
|
|
238
|
+
interface CommandHandle {
|
|
239
|
+
pid: number;
|
|
240
|
+
/** Sends SIGTERM to the process. Returns false if it had already exited. */
|
|
241
|
+
kill(): Promise<boolean>;
|
|
242
|
+
}
|
|
243
|
+
declare class Commands {
|
|
244
|
+
private readonly http;
|
|
245
|
+
private readonly sandboxId;
|
|
246
|
+
private readonly defaultEnvs;
|
|
247
|
+
/** @internal */
|
|
248
|
+
constructor(http: HttpClient, sandboxId: string, defaultEnvs: Record<string, string>);
|
|
249
|
+
/**
|
|
250
|
+
* Runs a shell command in the sandbox and waits for it to finish.
|
|
251
|
+
* Throws `CommandExitError` (carrying stdout, stderr and exitCode) when it exits non-zero.
|
|
252
|
+
*/
|
|
253
|
+
run(cmd: string, opts: CommandOptions & {
|
|
254
|
+
background: true;
|
|
255
|
+
}): Promise<CommandHandle>;
|
|
256
|
+
run(cmd: string, opts?: CommandOptions & {
|
|
257
|
+
background?: false;
|
|
258
|
+
}): Promise<CommandResult>;
|
|
259
|
+
run(cmd: string, opts?: CommandOptions): Promise<CommandResult | CommandHandle>;
|
|
260
|
+
/** @internal Raw exec: never throws on a non-zero exit code. */
|
|
261
|
+
exec(cmd: string, opts?: Pick<CommandOptions, 'cwd' | 'envs' | 'timeoutMs' | 'stdin'>): Promise<CommandResult>;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/** Largest file `files.read` / `files.write` move (files go through exec as base64). */
|
|
265
|
+
declare const MAX_FILE_BYTES: number;
|
|
266
|
+
interface EntryInfo {
|
|
267
|
+
name: string;
|
|
268
|
+
path: string;
|
|
269
|
+
type: 'file' | 'dir';
|
|
270
|
+
}
|
|
271
|
+
interface WriteInfo {
|
|
272
|
+
path: string;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* File access inside the sandbox. Implemented on top of exec (base64 over the command
|
|
276
|
+
* channel), capped at 10 MiB per file.
|
|
277
|
+
*/
|
|
278
|
+
declare class Files {
|
|
279
|
+
private readonly commands;
|
|
280
|
+
/** @internal */
|
|
281
|
+
constructor(commands: Commands);
|
|
282
|
+
/** Reads a file. Returns text (UTF-8) by default, or bytes with `{ format: 'bytes' }`. */
|
|
283
|
+
read(path: string, opts?: {
|
|
284
|
+
format?: 'text';
|
|
285
|
+
}): Promise<string>;
|
|
286
|
+
read(path: string, opts: {
|
|
287
|
+
format: 'bytes';
|
|
288
|
+
}): Promise<Uint8Array>;
|
|
289
|
+
/** Writes a file, creating parent directories. Replaces the file atomically (temp file + rename). */
|
|
290
|
+
write(path: string, data: string | Uint8Array): Promise<WriteInfo>;
|
|
291
|
+
/** Lists the entries of a directory (not recursive). */
|
|
292
|
+
list(path: string): Promise<EntryInfo[]>;
|
|
293
|
+
/** Removes a file or a directory (recursively). Missing paths are fine. */
|
|
294
|
+
remove(path: string): Promise<void>;
|
|
295
|
+
/** True if a file or directory exists at `path`. */
|
|
296
|
+
exists(path: string): Promise<boolean>;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
declare const DEFAULT_TEMPLATE = "universal";
|
|
300
|
+
interface SandboxOpts extends ConnectionOptions {
|
|
301
|
+
/** Machine name. Default `sbx-<random>`. */
|
|
302
|
+
name?: string;
|
|
303
|
+
/** String labels stored with the sandbox; filter on them with `Sandbox.list({ metadata })`. */
|
|
304
|
+
metadata?: Record<string, string>;
|
|
305
|
+
/** Environment variables applied to every `commands.run` of this Sandbox object (client-side). */
|
|
306
|
+
envs?: Record<string, string>;
|
|
307
|
+
/**
|
|
308
|
+
* The server pauses (or with `onTimeout: 'kill'` deletes) the sandbox this long after creation.
|
|
309
|
+
* Sent as whole seconds, 60 s to 24 h. Default: no timeout. Change it with `setTimeout()`.
|
|
310
|
+
*/
|
|
311
|
+
timeoutMs?: number;
|
|
312
|
+
/** What happens at the timeout: `pause` (default) or `kill`. */
|
|
313
|
+
onTimeout?: OnTimeout;
|
|
314
|
+
/** Stop and archive after this many milliseconds, independent of the pause/kill timeout. */
|
|
315
|
+
archiveMs?: number;
|
|
316
|
+
/** vCPUs. Default: the template's. */
|
|
317
|
+
vcpus?: number;
|
|
318
|
+
/** Memory in MiB. Default: the template's. */
|
|
319
|
+
memMiB?: number;
|
|
320
|
+
/** Size of the persistent `/data` disk in GiB. Default: the template's. */
|
|
321
|
+
diskGiB?: number;
|
|
322
|
+
/** Root disk size in GiB; may only grow. */
|
|
323
|
+
rootDiskGiB?: number;
|
|
324
|
+
}
|
|
325
|
+
interface SandboxConnectOpts extends ConnectionOptions {
|
|
326
|
+
/** Resume the sandbox if it is paused (suspended) or stopped. Default true. */
|
|
327
|
+
resume?: boolean;
|
|
328
|
+
envs?: Record<string, string>;
|
|
329
|
+
}
|
|
330
|
+
interface SandboxListOpts extends ConnectionOptions {
|
|
331
|
+
/** Only sandboxes whose metadata has every one of these key/value pairs. */
|
|
332
|
+
metadata?: Record<string, string>;
|
|
333
|
+
}
|
|
334
|
+
interface SandboxInfo {
|
|
335
|
+
sandboxId: string;
|
|
336
|
+
/** Template the sandbox runs (`template.id`). */
|
|
337
|
+
templateId: string;
|
|
338
|
+
/** Snapshot the sandbox was created from, if any. */
|
|
339
|
+
snapshotId?: string;
|
|
340
|
+
name: string;
|
|
341
|
+
/** String labels stored with the sandbox. */
|
|
342
|
+
metadata: Record<string, string>;
|
|
343
|
+
/** Creation time of the machine. */
|
|
344
|
+
startedAt: Date;
|
|
345
|
+
/** When the server pauses or kills the sandbox (see `onTimeout`); undefined for no timeout. */
|
|
346
|
+
endAt?: Date;
|
|
347
|
+
archiveAt?: Date;
|
|
348
|
+
onTimeout: OnTimeout;
|
|
349
|
+
state: MachineState;
|
|
350
|
+
/** The raw machine object from the API. */
|
|
351
|
+
machine: Machine;
|
|
352
|
+
}
|
|
353
|
+
interface ForkOpts {
|
|
354
|
+
/** Name of the new sandbox. Default `<name>-fork-<random>`. */
|
|
355
|
+
name?: string;
|
|
356
|
+
vcpus?: number;
|
|
357
|
+
memMiB?: number;
|
|
358
|
+
/** May only grow. */
|
|
359
|
+
diskGiB?: number;
|
|
360
|
+
/** Root disk size in GiB; may only grow. */
|
|
361
|
+
rootDiskGiB?: number;
|
|
362
|
+
/** Timeout of the copy, as in `SandboxOpts.timeoutMs`. Default: none (the source's is not copied). */
|
|
363
|
+
timeoutMs?: number;
|
|
364
|
+
onTimeout?: OnTimeout;
|
|
365
|
+
/** Metadata of the copy. Default: the source's; `{}` for none. */
|
|
366
|
+
metadata?: Record<string, string>;
|
|
367
|
+
/**
|
|
368
|
+
* A fork needs a stopped source. When true (default), `fork()` stops the source first if needed
|
|
369
|
+
* (running processes end, `/data` is kept) and leaves it stopped; call `resume()` to start it again.
|
|
370
|
+
* When false, a source that is not stopped makes the call fail.
|
|
371
|
+
*/
|
|
372
|
+
stopSource?: boolean;
|
|
373
|
+
}
|
|
374
|
+
interface CreateSnapshotOpts {
|
|
375
|
+
name: string;
|
|
376
|
+
description?: string;
|
|
377
|
+
/** Save only the root disk; omit the persistent /data disk. */
|
|
378
|
+
rootOnly?: boolean;
|
|
379
|
+
}
|
|
380
|
+
interface SshCredentials {
|
|
381
|
+
host: string;
|
|
382
|
+
port: number;
|
|
383
|
+
/** The machine ID. */
|
|
384
|
+
username: string;
|
|
385
|
+
/** OpenSSH user certificate for `publicKey`, in authorized_keys format. Save it as `<key>-cert.pub`. */
|
|
386
|
+
certificate: string;
|
|
387
|
+
/** Line for known_hosts that trusts the instabox gateway: `@cert-authority [host]:port <ca key>`. */
|
|
388
|
+
knownHostsLine: string;
|
|
389
|
+
expiresAt: Date;
|
|
390
|
+
connectionId: string;
|
|
391
|
+
}
|
|
392
|
+
/** A instabox dev machine. Create one with `Sandbox.create()` or attach with `Sandbox.connect(id)`. */
|
|
393
|
+
declare class Sandbox {
|
|
394
|
+
private readonly http;
|
|
395
|
+
/** The machine ID (`m_...`). */
|
|
396
|
+
readonly sandboxId: string;
|
|
397
|
+
/** Run shell commands. Needs a instabox server with the exec endpoint. */
|
|
398
|
+
readonly commands: Commands;
|
|
399
|
+
/** Read and write files. Needs a instabox server with the exec endpoint. */
|
|
400
|
+
readonly files: Files;
|
|
401
|
+
private machine;
|
|
402
|
+
private constructor();
|
|
403
|
+
/**
|
|
404
|
+
* Creates a sandbox and waits until it is running.
|
|
405
|
+
* `template` is a template ID, a private snapshot name or a snapshot ID (`sn_...`).
|
|
406
|
+
* Template IDs take precedence over snapshot names. Default template: `universal`.
|
|
407
|
+
*/
|
|
408
|
+
static create(opts?: SandboxOpts): Promise<Sandbox>;
|
|
409
|
+
static create(template: string, opts?: SandboxOpts): Promise<Sandbox>;
|
|
410
|
+
/** Attaches to an existing sandbox. Resumes it if it is paused or stopped, unless `resume: false`. */
|
|
411
|
+
static connect(sandboxId: string, opts?: SandboxConnectOpts): Promise<Sandbox>;
|
|
412
|
+
/** Lists your sandboxes (all pages), optionally only those matching `metadata`. */
|
|
413
|
+
static list(opts?: SandboxListOpts): Promise<SandboxInfo[]>;
|
|
414
|
+
/** Deletes a sandbox and its disks. Returns false if it did not exist. */
|
|
415
|
+
static kill(sandboxId: string, opts?: ConnectionOptions): Promise<boolean>;
|
|
416
|
+
/** Lists the caller's private snapshots. Requires images:read. */
|
|
417
|
+
static listSnapshots(opts?: ConnectionOptions): Promise<Snapshot[]>;
|
|
418
|
+
/** Fetches a snapshot by ID. Requires images:read. */
|
|
419
|
+
static getSnapshot(snapshotId: string, opts?: ConnectionOptions): Promise<Snapshot>;
|
|
420
|
+
/** Deletes a snapshot. Returns false if absent. Requires images:delete. */
|
|
421
|
+
static deleteSnapshot(snapshotId: string, opts?: ConnectionOptions): Promise<boolean>;
|
|
422
|
+
/** Saves a stopped sandbox's disks as a private snapshot. Requires images:write. */
|
|
423
|
+
createSnapshot(opts: CreateSnapshotOpts): Promise<Snapshot>;
|
|
424
|
+
/** Fetches the current state of the sandbox. */
|
|
425
|
+
getInfo(): Promise<SandboxInfo>;
|
|
426
|
+
/**
|
|
427
|
+
* Sets the timeout to `timeoutMs` from now (whole seconds, 60 s to 24 h); 0 clears it.
|
|
428
|
+
* `onTimeout` changes what happens then (`pause` or `kill`).
|
|
429
|
+
*/
|
|
430
|
+
setTimeout(timeoutMs: number, opts?: {
|
|
431
|
+
onTimeout?: OnTimeout;
|
|
432
|
+
}): Promise<void>;
|
|
433
|
+
/** Replaces the sandbox's metadata (`{}` clears it). */
|
|
434
|
+
setMetadata(metadata: Record<string, string>): Promise<void>;
|
|
435
|
+
/** True if the sandbox is running (fetches fresh state). */
|
|
436
|
+
isRunning(): Promise<boolean>;
|
|
437
|
+
/** Snapshots memory and stops the sandbox (suspend). `resume()` or `Sandbox.connect()` brings it back. */
|
|
438
|
+
pause(): Promise<void>;
|
|
439
|
+
/** Resumes a paused sandbox from its snapshot, or starts a stopped one. */
|
|
440
|
+
resume(): Promise<void>;
|
|
441
|
+
/** Resumes or starts based on the cached state; callers make sure the cache is fresh. */
|
|
442
|
+
private wake;
|
|
443
|
+
/** Stops the sandbox (guest shutdown; processes end, `/data` is kept). */
|
|
444
|
+
stop(): Promise<void>;
|
|
445
|
+
/** Copies this sandbox (root disk and `/data`) into a new sandbox and waits until it runs. */
|
|
446
|
+
fork(opts?: ForkOpts): Promise<Sandbox>;
|
|
447
|
+
/** Deletes the sandbox and its disks. Returns false if it was already gone. */
|
|
448
|
+
kill(): Promise<boolean>;
|
|
449
|
+
/**
|
|
450
|
+
* Issues a short-lived SSH certificate for `publicKey` (authorized_keys format).
|
|
451
|
+
* Connect with `ssh -p <port> -o CertificateFile=<cert> -i <key> <username>@<host>` after adding
|
|
452
|
+
* `knownHostsLine` to known_hosts. The sandbox must be running.
|
|
453
|
+
*/
|
|
454
|
+
sshCredentials(publicKey: string, opts?: {
|
|
455
|
+
ttlSeconds?: number;
|
|
456
|
+
}): Promise<SshCredentials>;
|
|
457
|
+
/**
|
|
458
|
+
* Re-reads the machine from the server (other handles or the dashboard may have changed it),
|
|
459
|
+
* waits for its active operation if one is running, and leaves the fresh state cached.
|
|
460
|
+
* Every state-dependent method calls this first, so it never decides from a stale cache.
|
|
461
|
+
*/
|
|
462
|
+
private settle;
|
|
463
|
+
private mutate;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
export { type ApiError, CommandExitError, type CommandHandle, type CommandOptions, type CommandResult, Commands, type Connection, type ConnectionOptions, type CreateSnapshotOpts, DEFAULT_API_URL, DEFAULT_TEMPLATE, type EntryInfo, type ExecResponse, Files, type ForkOpts, type HostTrust, InstaboxAuthError, InstaboxError, type InstaboxErrorInit, InstaboxQuotaError, InstaboxTimeoutError, MAX_FILE_BYTES, type Machine, type MachineList, type MachineSpec, type MachineState, type OnTimeout, type Operation, Sandbox, type SandboxConnectOpts, type SandboxInfo, type SandboxListOpts, type SandboxOpts, type Snapshot, type SnapshotList, type SshCredentials, type Template, type TemplateRef, type WriteInfo };
|