@insforge/instabox-sdk 0.1.1 → 0.2.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/README.md +62 -25
- package/dist/index.cjs +152 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +135 -17
- package/dist/index.d.ts +135 -17
- package/dist/index.js +152 -23
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/skills/instabox/SKILL.md +27 -14
package/dist/index.d.cts
CHANGED
|
@@ -19,7 +19,7 @@ declare class InstaboxError extends Error {
|
|
|
19
19
|
readonly operationId?: string | null;
|
|
20
20
|
constructor(message: string, init?: InstaboxErrorInit);
|
|
21
21
|
}
|
|
22
|
-
/** 401 / 403:
|
|
22
|
+
/** 401 / 403: invalid or revoked API key, or not allowed. Also no API key at all (`missing_api_key`, status 0). */
|
|
23
23
|
declare class InstaboxAuthError extends InstaboxError {
|
|
24
24
|
}
|
|
25
25
|
/** 429 `quota_exceeded`: an account limit was reached (for example the machine limit). */
|
|
@@ -100,11 +100,59 @@ interface Machine {
|
|
|
100
100
|
timeoutAt?: string | null;
|
|
101
101
|
archiveAt?: string | null;
|
|
102
102
|
onTimeout?: OnTimeout;
|
|
103
|
+
/** Idle seconds after which the server pauses the running machine; null when it never does. */
|
|
104
|
+
autoSuspendAfterSeconds?: number | null;
|
|
105
|
+
/** When the server paused it for idleness; cleared by the next explicit operation. */
|
|
106
|
+
autoSuspendedAt?: string | null;
|
|
103
107
|
/** String labels, stored by the server. */
|
|
104
108
|
metadata?: Record<string, string>;
|
|
109
|
+
/**
|
|
110
|
+
* The machine gets the account's Vault items at every boot and resume; false, once set, is for good.
|
|
111
|
+
* Absent on servers without the Vault: treat as true.
|
|
112
|
+
*/
|
|
113
|
+
vault?: boolean;
|
|
105
114
|
createdAt: string;
|
|
106
115
|
updatedAt: string;
|
|
107
116
|
}
|
|
117
|
+
/** One Vault item a machine gets (`GET /v1/machines/{id}/vault`). Values are never returned. */
|
|
118
|
+
interface MachineVaultItem {
|
|
119
|
+
name: string;
|
|
120
|
+
/** `env`: a variable exported to every login shell. `file`: a file at `path` under the home directory. */
|
|
121
|
+
kind: 'env' | 'file';
|
|
122
|
+
path?: string;
|
|
123
|
+
}
|
|
124
|
+
/** A file the Vault wrote: its home-relative path and the sha256 (hex) of its content. */
|
|
125
|
+
interface VaultFile {
|
|
126
|
+
path: string;
|
|
127
|
+
sha256: string;
|
|
128
|
+
}
|
|
129
|
+
/** A file that no longer applies but was left in place (changed in the sandbox since, or not writable). */
|
|
130
|
+
interface VaultKept {
|
|
131
|
+
path: string;
|
|
132
|
+
reason: string;
|
|
133
|
+
}
|
|
134
|
+
/** One write of the Vault into a machine. */
|
|
135
|
+
interface VaultApplied {
|
|
136
|
+
at: string;
|
|
137
|
+
/** The variables exported. */
|
|
138
|
+
env: string[];
|
|
139
|
+
/** The files written (or, when the write failed, those of the last write). */
|
|
140
|
+
files: VaultFile[];
|
|
141
|
+
/** Files of an earlier write removed because they no longer apply. */
|
|
142
|
+
removed?: string[];
|
|
143
|
+
kept?: VaultKept[];
|
|
144
|
+
/** Why the write failed, when it did. */
|
|
145
|
+
error?: string;
|
|
146
|
+
}
|
|
147
|
+
/** Response of `GET /v1/machines/{id}/vault`. */
|
|
148
|
+
interface MachineVault {
|
|
149
|
+
/** The machine takes the Vault. */
|
|
150
|
+
enabled: boolean;
|
|
151
|
+
/** The items that apply with the machine's current metadata (none when `enabled` is false). */
|
|
152
|
+
items: MachineVaultItem[];
|
|
153
|
+
/** The last write into the machine; null before one. */
|
|
154
|
+
applied: VaultApplied | null;
|
|
155
|
+
}
|
|
108
156
|
/** What happens at `timeoutAt`: `pause` suspends the machine, `kill` deletes it. */
|
|
109
157
|
type OnTimeout = 'pause' | 'kill';
|
|
110
158
|
interface MachineList {
|
|
@@ -133,6 +181,8 @@ interface Snapshot {
|
|
|
133
181
|
dataSizeBytes?: number;
|
|
134
182
|
exclusiveBytes?: number;
|
|
135
183
|
defaultSpec?: MachineSpec;
|
|
184
|
+
/** `pending` while a snapshot of a running sandbox is being saved (creating from it waits), then `ready`. */
|
|
185
|
+
status?: 'pending' | 'ready' | (string & {});
|
|
136
186
|
createdAt: string;
|
|
137
187
|
}
|
|
138
188
|
interface Template {
|
|
@@ -141,6 +191,8 @@ interface Template {
|
|
|
141
191
|
digest: string;
|
|
142
192
|
arch: string;
|
|
143
193
|
defaultSpec: MachineSpec;
|
|
194
|
+
/** True when the server's release no longer builds it: listed, but new sandboxes are refused. */
|
|
195
|
+
hidden?: boolean;
|
|
144
196
|
}
|
|
145
197
|
interface SnapshotList {
|
|
146
198
|
snapshots: Snapshot[];
|
|
@@ -171,12 +223,12 @@ interface ExecResponse {
|
|
|
171
223
|
error?: string;
|
|
172
224
|
}
|
|
173
225
|
|
|
174
|
-
declare const DEFAULT_API_URL = "https://api.
|
|
226
|
+
declare const DEFAULT_API_URL = "https://api.instabox.sh";
|
|
175
227
|
/** Options shared by every call that talks to the API. */
|
|
176
228
|
interface ConnectionOptions {
|
|
177
229
|
/** API key from the instabox dashboard's API Keys page. Default: env `INSTABOX_API_KEY`. */
|
|
178
230
|
apiKey?: string;
|
|
179
|
-
/** API base URL. Default: env `INSTABOX_API_URL`, else `https://api.
|
|
231
|
+
/** API base URL. Default: env `INSTABOX_API_URL`, else `https://api.instabox.sh`. */
|
|
180
232
|
apiUrl?: string;
|
|
181
233
|
/** Timeout of a single HTTP request in ms. Default 60 000; exec defaults to its command timeout plus 30 000. */
|
|
182
234
|
requestTimeoutMs?: number;
|
|
@@ -204,7 +256,7 @@ declare class HttpClient {
|
|
|
204
256
|
private readonly apiKey;
|
|
205
257
|
private readonly requestTimeoutMs?;
|
|
206
258
|
private readonly fetchImpl;
|
|
207
|
-
|
|
259
|
+
readonly pollIntervalMs: number;
|
|
208
260
|
private readonly retryDelayMs;
|
|
209
261
|
constructor(opts?: ConnectionOptions);
|
|
210
262
|
request<T>(method: string, path: string, opts?: RequestOptions): Promise<T>;
|
|
@@ -215,6 +267,8 @@ declare class HttpClient {
|
|
|
215
267
|
waitForOperation(op: Operation, timeoutMs?: number): Promise<Operation>;
|
|
216
268
|
}
|
|
217
269
|
|
|
270
|
+
/** The API's limit on `stdin`, in UTF-8 bytes. */
|
|
271
|
+
declare const MAX_STDIN_BYTES: number;
|
|
218
272
|
interface CommandOptions {
|
|
219
273
|
/** Working directory. Default: the server's default (HOME, `/data/home`). */
|
|
220
274
|
cwd?: string;
|
|
@@ -222,22 +276,23 @@ interface CommandOptions {
|
|
|
222
276
|
envs?: Record<string, string>;
|
|
223
277
|
/** Command timeout in ms (sent as whole seconds). Default: the server's default. */
|
|
224
278
|
timeoutMs?: number;
|
|
225
|
-
/** Text sent to the command's standard input. */
|
|
279
|
+
/** Text sent to the command's standard input, at most 1 MiB (UTF-8). */
|
|
226
280
|
stdin?: string;
|
|
227
281
|
/**
|
|
228
282
|
* Called with stdout once the command finished. Output is not streamed yet:
|
|
229
283
|
* the callback receives the whole stdout in one call.
|
|
230
284
|
*/
|
|
231
|
-
onStdout?: (data: string) =>
|
|
285
|
+
onStdout?: (data: string) => unknown;
|
|
232
286
|
/** Like `onStdout`, for stderr. */
|
|
233
|
-
onStderr?: (data: string) =>
|
|
234
|
-
/** Start the command detached (nohup) and return right away with its PID. */
|
|
287
|
+
onStderr?: (data: string) => unknown;
|
|
288
|
+
/** Start the command detached (nohup, in its own session) and return right away with its PID. */
|
|
235
289
|
background?: boolean;
|
|
236
290
|
}
|
|
237
291
|
/** A command started with `background: true`. */
|
|
238
292
|
interface CommandHandle {
|
|
293
|
+
/** PID of the command's shell, which leads the process group of everything it started. */
|
|
239
294
|
pid: number;
|
|
240
|
-
/** Sends SIGTERM to the process. Returns false if
|
|
295
|
+
/** Sends SIGTERM to the command and every process it started. Returns false if they had all exited. */
|
|
241
296
|
kill(): Promise<boolean>;
|
|
242
297
|
}
|
|
243
298
|
declare class Commands {
|
|
@@ -286,7 +341,10 @@ declare class Files {
|
|
|
286
341
|
read(path: string, opts: {
|
|
287
342
|
format: 'bytes';
|
|
288
343
|
}): Promise<Uint8Array>;
|
|
289
|
-
/**
|
|
344
|
+
/**
|
|
345
|
+
* Writes a file, creating parent directories. Replaces the file atomically (temp file + rename).
|
|
346
|
+
* Throws `is_a_directory` when `path` is a directory.
|
|
347
|
+
*/
|
|
290
348
|
write(path: string, data: string | Uint8Array): Promise<WriteInfo>;
|
|
291
349
|
/** Lists the entries of a directory (not recursive). */
|
|
292
350
|
list(path: string): Promise<EntryInfo[]>;
|
|
@@ -296,9 +354,11 @@ declare class Files {
|
|
|
296
354
|
exists(path: string): Promise<boolean>;
|
|
297
355
|
}
|
|
298
356
|
|
|
299
|
-
declare const DEFAULT_TEMPLATE = "
|
|
357
|
+
declare const DEFAULT_TEMPLATE = "agent-browser";
|
|
358
|
+
/** The default when a server does not offer `DEFAULT_TEMPLATE` (an older or self-hosted one). */
|
|
359
|
+
declare const FALLBACK_TEMPLATE = "universal";
|
|
300
360
|
interface SandboxOpts extends ConnectionOptions {
|
|
301
|
-
/** Machine name
|
|
361
|
+
/** Machine name: lowercase letters, digits and `-`. Default `sbx-<random>`. */
|
|
302
362
|
name?: string;
|
|
303
363
|
/** String labels stored with the sandbox; filter on them with `Sandbox.list({ metadata })`. */
|
|
304
364
|
metadata?: Record<string, string>;
|
|
@@ -313,7 +373,14 @@ interface SandboxOpts extends ConnectionOptions {
|
|
|
313
373
|
onTimeout?: OnTimeout;
|
|
314
374
|
/** Stop and archive after this many milliseconds, independent of the pause/kill timeout. */
|
|
315
375
|
archiveMs?: number;
|
|
316
|
-
/**
|
|
376
|
+
/**
|
|
377
|
+
* The server pauses the sandbox once it has been idle this long (no agent working, no terminal use,
|
|
378
|
+
* little CPU); the next command, file read or SSH sign-in resumes it. Sent as whole seconds, 2 min to
|
|
379
|
+
* 24 h. Default: 30 minutes. `0`: never, the sandbox stays on until paused or killed. Change it later
|
|
380
|
+
* with `setAutoSuspend()`.
|
|
381
|
+
*/
|
|
382
|
+
autoSuspendMs?: number;
|
|
383
|
+
/** vCPUs. Default: the template's. Services with fixed sizes (api.instabox.sh) refuse the size options. */
|
|
317
384
|
vcpus?: number;
|
|
318
385
|
/** Memory in MiB. Default: the template's. */
|
|
319
386
|
memMiB?: number;
|
|
@@ -321,6 +388,13 @@ interface SandboxOpts extends ConnectionOptions {
|
|
|
321
388
|
diskGiB?: number;
|
|
322
389
|
/** Root disk size in GiB; may only grow. */
|
|
323
390
|
rootDiskGiB?: number;
|
|
391
|
+
/**
|
|
392
|
+
* `false`: the sandbox never gets the account's Vault items (the secrets the dashboard's Vault page or
|
|
393
|
+
* `instabox vault set` keeps, written into every sandbox of the account at boot and resume). Pass it for
|
|
394
|
+
* sandboxes made for other people: anything running in a sandbox can read what the Vault writes into it.
|
|
395
|
+
* Default: the sandbox gets them. Cannot be turned on again later.
|
|
396
|
+
*/
|
|
397
|
+
vault?: boolean;
|
|
324
398
|
}
|
|
325
399
|
interface SandboxConnectOpts extends ConnectionOptions {
|
|
326
400
|
/** Resume the sandbox if it is paused (suspended) or stopped. Default true. */
|
|
@@ -340,12 +414,16 @@ interface SandboxInfo {
|
|
|
340
414
|
name: string;
|
|
341
415
|
/** String labels stored with the sandbox. */
|
|
342
416
|
metadata: Record<string, string>;
|
|
417
|
+
/** The sandbox gets the account's Vault items at boot and resume (`vault: false` at creation, or `disableVault()`, turns this off for good). */
|
|
418
|
+
vault: boolean;
|
|
343
419
|
/** Creation time of the machine. */
|
|
344
420
|
startedAt: Date;
|
|
345
421
|
/** When the server pauses or kills the sandbox (see `onTimeout`); undefined for no timeout. */
|
|
346
422
|
endAt?: Date;
|
|
347
423
|
archiveAt?: Date;
|
|
348
424
|
onTimeout: OnTimeout;
|
|
425
|
+
/** Idle time after which the server pauses the sandbox; undefined when it never does. */
|
|
426
|
+
autoSuspendMs?: number;
|
|
349
427
|
state: MachineState;
|
|
350
428
|
/** The raw machine object from the API. */
|
|
351
429
|
machine: Machine;
|
|
@@ -362,8 +440,12 @@ interface ForkOpts {
|
|
|
362
440
|
/** Timeout of the copy, as in `SandboxOpts.timeoutMs`. Default: none (the source's is not copied). */
|
|
363
441
|
timeoutMs?: number;
|
|
364
442
|
onTimeout?: OnTimeout;
|
|
443
|
+
/** Idle pause of the copy, as in `SandboxOpts.autoSuspendMs`. Default: 30 minutes (the source's is not copied); `0`: never. */
|
|
444
|
+
autoSuspendMs?: number;
|
|
365
445
|
/** Metadata of the copy. Default: the source's; `{}` for none. */
|
|
366
446
|
metadata?: Record<string, string>;
|
|
447
|
+
/** `false`: the copy never gets the account's Vault items (a copy of a sandbox without the Vault never does). */
|
|
448
|
+
vault?: boolean;
|
|
367
449
|
/**
|
|
368
450
|
* A fork needs a stopped source. When true (default), `fork()` stops the source first if needed
|
|
369
451
|
* (running processes end, `/data` is kept) and leaves it stopped; call `resume()` to start it again.
|
|
@@ -403,7 +485,10 @@ declare class Sandbox {
|
|
|
403
485
|
/**
|
|
404
486
|
* Creates a sandbox and waits until it is running.
|
|
405
487
|
* `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
|
|
488
|
+
* Template IDs take precedence over snapshot names. Default template: `agent-browser` (universal
|
|
489
|
+
* with a desktop and browser preinstalled, which the dashboard's Computer tab shows), or
|
|
490
|
+
* `universal` on a server that does not offer it. A snapshot that is still being saved is waited
|
|
491
|
+
* for (up to `operationTimeoutMs`).
|
|
407
492
|
*/
|
|
408
493
|
static create(opts?: SandboxOpts): Promise<Sandbox>;
|
|
409
494
|
static create(template: string, opts?: SandboxOpts): Promise<Sandbox>;
|
|
@@ -419,7 +504,11 @@ declare class Sandbox {
|
|
|
419
504
|
static getSnapshot(snapshotId: string, opts?: ConnectionOptions): Promise<Snapshot>;
|
|
420
505
|
/** Deletes a snapshot. Returns false if absent. Requires images:delete. */
|
|
421
506
|
static deleteSnapshot(snapshotId: string, opts?: ConnectionOptions): Promise<boolean>;
|
|
422
|
-
/**
|
|
507
|
+
/**
|
|
508
|
+
* Saves the sandbox's disks as a private snapshot. Requires images:write. The sandbox may be running;
|
|
509
|
+
* the snapshot is then returned with `status: 'pending'` and becomes `ready` once saved. For a stopped
|
|
510
|
+
* sandbox it waits first for a recent stop's upload to object storage (see `untilSynced`).
|
|
511
|
+
*/
|
|
423
512
|
createSnapshot(opts: CreateSnapshotOpts): Promise<Snapshot>;
|
|
424
513
|
/** Fetches the current state of the sandbox. */
|
|
425
514
|
getInfo(): Promise<SandboxInfo>;
|
|
@@ -430,8 +519,29 @@ declare class Sandbox {
|
|
|
430
519
|
setTimeout(timeoutMs: number, opts?: {
|
|
431
520
|
onTimeout?: OnTimeout;
|
|
432
521
|
}): Promise<void>;
|
|
522
|
+
/**
|
|
523
|
+
* Pauses the sandbox once it has been idle `idleMs` (whole seconds, 2 min to 24 h); 0 turns the idle
|
|
524
|
+
* pause off. Unlike a timeout the setting stays across pause and resume.
|
|
525
|
+
*/
|
|
526
|
+
setAutoSuspend(idleMs: number): Promise<void>;
|
|
433
527
|
/** Replaces the sandbox's metadata (`{}` clears it). */
|
|
434
528
|
setMetadata(metadata: Record<string, string>): Promise<void>;
|
|
529
|
+
/**
|
|
530
|
+
* What the Vault writes into this sandbox: whether it takes the Vault, the items that apply with its
|
|
531
|
+
* current metadata (names and paths, never values) and the last write. Requires machines:read.
|
|
532
|
+
* Throws `not_found` on a server without the Vault.
|
|
533
|
+
*/
|
|
534
|
+
vault(): Promise<MachineVault>;
|
|
535
|
+
/**
|
|
536
|
+
* Writes the account's current Vault items into the running sandbox now, the same write as after a boot,
|
|
537
|
+
* and returns its record (`error` set when the guest refused it). Requires machines:write.
|
|
538
|
+
*/
|
|
539
|
+
pushVault(): Promise<VaultApplied>;
|
|
540
|
+
/**
|
|
541
|
+
* Turns the Vault off for this sandbox, for good, in any state: its next boot, resume or push removes
|
|
542
|
+
* what the Vault wrote and nothing is written again. Requires machines:write.
|
|
543
|
+
*/
|
|
544
|
+
disableVault(): Promise<void>;
|
|
435
545
|
/** True if the sandbox is running (fetches fresh state). */
|
|
436
546
|
isRunning(): Promise<boolean>;
|
|
437
547
|
/** Snapshots memory and stops the sandbox (suspend). `resume()` or `Sandbox.connect()` brings it back. */
|
|
@@ -449,7 +559,8 @@ declare class Sandbox {
|
|
|
449
559
|
/**
|
|
450
560
|
* Issues a short-lived SSH certificate for `publicKey` (authorized_keys format).
|
|
451
561
|
* Connect with `ssh -p <port> -o CertificateFile=<cert> -i <key> <username>@<host>` after adding
|
|
452
|
-
* `knownHostsLine` to known_hosts. The sandbox must be running.
|
|
562
|
+
* `knownHostsLine` to known_hosts. The sandbox must be running. `ttlSeconds`: 1 to 86 400 (24 h);
|
|
563
|
+
* default: the server's (1 h).
|
|
453
564
|
*/
|
|
454
565
|
sshCredentials(publicKey: string, opts?: {
|
|
455
566
|
ttlSeconds?: number;
|
|
@@ -460,7 +571,14 @@ declare class Sandbox {
|
|
|
460
571
|
* Every state-dependent method calls this first, so it never decides from a stale cache.
|
|
461
572
|
*/
|
|
462
573
|
private settle;
|
|
574
|
+
/**
|
|
575
|
+
* Waits until a stopped sandbox's disks are in object storage (`storage.synced`). A stop returns
|
|
576
|
+
* once the host has the snapshot and uploads it after, so a fork or snapshot right after a stop
|
|
577
|
+
* was refused ("not uploaded to object storage"), which took long enough after a pause and resume
|
|
578
|
+
* to fail every time. Only a stopped sandbox is waited for; the server says what else is wrong.
|
|
579
|
+
*/
|
|
580
|
+
private untilSynced;
|
|
463
581
|
private mutate;
|
|
464
582
|
}
|
|
465
583
|
|
|
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 };
|
|
584
|
+
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, FALLBACK_TEMPLATE, Files, type ForkOpts, type HostTrust, InstaboxAuthError, InstaboxError, type InstaboxErrorInit, InstaboxQuotaError, InstaboxTimeoutError, MAX_FILE_BYTES, MAX_STDIN_BYTES, type Machine, type MachineList, type MachineSpec, type MachineState, type MachineVault, type MachineVaultItem, type OnTimeout, type Operation, Sandbox, type SandboxConnectOpts, type SandboxInfo, type SandboxListOpts, type SandboxOpts, type Snapshot, type SnapshotList, type SshCredentials, type Template, type TemplateRef, type VaultApplied, type VaultFile, type VaultKept, type WriteInfo };
|
package/dist/index.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ declare class InstaboxError extends Error {
|
|
|
19
19
|
readonly operationId?: string | null;
|
|
20
20
|
constructor(message: string, init?: InstaboxErrorInit);
|
|
21
21
|
}
|
|
22
|
-
/** 401 / 403:
|
|
22
|
+
/** 401 / 403: invalid or revoked API key, or not allowed. Also no API key at all (`missing_api_key`, status 0). */
|
|
23
23
|
declare class InstaboxAuthError extends InstaboxError {
|
|
24
24
|
}
|
|
25
25
|
/** 429 `quota_exceeded`: an account limit was reached (for example the machine limit). */
|
|
@@ -100,11 +100,59 @@ interface Machine {
|
|
|
100
100
|
timeoutAt?: string | null;
|
|
101
101
|
archiveAt?: string | null;
|
|
102
102
|
onTimeout?: OnTimeout;
|
|
103
|
+
/** Idle seconds after which the server pauses the running machine; null when it never does. */
|
|
104
|
+
autoSuspendAfterSeconds?: number | null;
|
|
105
|
+
/** When the server paused it for idleness; cleared by the next explicit operation. */
|
|
106
|
+
autoSuspendedAt?: string | null;
|
|
103
107
|
/** String labels, stored by the server. */
|
|
104
108
|
metadata?: Record<string, string>;
|
|
109
|
+
/**
|
|
110
|
+
* The machine gets the account's Vault items at every boot and resume; false, once set, is for good.
|
|
111
|
+
* Absent on servers without the Vault: treat as true.
|
|
112
|
+
*/
|
|
113
|
+
vault?: boolean;
|
|
105
114
|
createdAt: string;
|
|
106
115
|
updatedAt: string;
|
|
107
116
|
}
|
|
117
|
+
/** One Vault item a machine gets (`GET /v1/machines/{id}/vault`). Values are never returned. */
|
|
118
|
+
interface MachineVaultItem {
|
|
119
|
+
name: string;
|
|
120
|
+
/** `env`: a variable exported to every login shell. `file`: a file at `path` under the home directory. */
|
|
121
|
+
kind: 'env' | 'file';
|
|
122
|
+
path?: string;
|
|
123
|
+
}
|
|
124
|
+
/** A file the Vault wrote: its home-relative path and the sha256 (hex) of its content. */
|
|
125
|
+
interface VaultFile {
|
|
126
|
+
path: string;
|
|
127
|
+
sha256: string;
|
|
128
|
+
}
|
|
129
|
+
/** A file that no longer applies but was left in place (changed in the sandbox since, or not writable). */
|
|
130
|
+
interface VaultKept {
|
|
131
|
+
path: string;
|
|
132
|
+
reason: string;
|
|
133
|
+
}
|
|
134
|
+
/** One write of the Vault into a machine. */
|
|
135
|
+
interface VaultApplied {
|
|
136
|
+
at: string;
|
|
137
|
+
/** The variables exported. */
|
|
138
|
+
env: string[];
|
|
139
|
+
/** The files written (or, when the write failed, those of the last write). */
|
|
140
|
+
files: VaultFile[];
|
|
141
|
+
/** Files of an earlier write removed because they no longer apply. */
|
|
142
|
+
removed?: string[];
|
|
143
|
+
kept?: VaultKept[];
|
|
144
|
+
/** Why the write failed, when it did. */
|
|
145
|
+
error?: string;
|
|
146
|
+
}
|
|
147
|
+
/** Response of `GET /v1/machines/{id}/vault`. */
|
|
148
|
+
interface MachineVault {
|
|
149
|
+
/** The machine takes the Vault. */
|
|
150
|
+
enabled: boolean;
|
|
151
|
+
/** The items that apply with the machine's current metadata (none when `enabled` is false). */
|
|
152
|
+
items: MachineVaultItem[];
|
|
153
|
+
/** The last write into the machine; null before one. */
|
|
154
|
+
applied: VaultApplied | null;
|
|
155
|
+
}
|
|
108
156
|
/** What happens at `timeoutAt`: `pause` suspends the machine, `kill` deletes it. */
|
|
109
157
|
type OnTimeout = 'pause' | 'kill';
|
|
110
158
|
interface MachineList {
|
|
@@ -133,6 +181,8 @@ interface Snapshot {
|
|
|
133
181
|
dataSizeBytes?: number;
|
|
134
182
|
exclusiveBytes?: number;
|
|
135
183
|
defaultSpec?: MachineSpec;
|
|
184
|
+
/** `pending` while a snapshot of a running sandbox is being saved (creating from it waits), then `ready`. */
|
|
185
|
+
status?: 'pending' | 'ready' | (string & {});
|
|
136
186
|
createdAt: string;
|
|
137
187
|
}
|
|
138
188
|
interface Template {
|
|
@@ -141,6 +191,8 @@ interface Template {
|
|
|
141
191
|
digest: string;
|
|
142
192
|
arch: string;
|
|
143
193
|
defaultSpec: MachineSpec;
|
|
194
|
+
/** True when the server's release no longer builds it: listed, but new sandboxes are refused. */
|
|
195
|
+
hidden?: boolean;
|
|
144
196
|
}
|
|
145
197
|
interface SnapshotList {
|
|
146
198
|
snapshots: Snapshot[];
|
|
@@ -171,12 +223,12 @@ interface ExecResponse {
|
|
|
171
223
|
error?: string;
|
|
172
224
|
}
|
|
173
225
|
|
|
174
|
-
declare const DEFAULT_API_URL = "https://api.
|
|
226
|
+
declare const DEFAULT_API_URL = "https://api.instabox.sh";
|
|
175
227
|
/** Options shared by every call that talks to the API. */
|
|
176
228
|
interface ConnectionOptions {
|
|
177
229
|
/** API key from the instabox dashboard's API Keys page. Default: env `INSTABOX_API_KEY`. */
|
|
178
230
|
apiKey?: string;
|
|
179
|
-
/** API base URL. Default: env `INSTABOX_API_URL`, else `https://api.
|
|
231
|
+
/** API base URL. Default: env `INSTABOX_API_URL`, else `https://api.instabox.sh`. */
|
|
180
232
|
apiUrl?: string;
|
|
181
233
|
/** Timeout of a single HTTP request in ms. Default 60 000; exec defaults to its command timeout plus 30 000. */
|
|
182
234
|
requestTimeoutMs?: number;
|
|
@@ -204,7 +256,7 @@ declare class HttpClient {
|
|
|
204
256
|
private readonly apiKey;
|
|
205
257
|
private readonly requestTimeoutMs?;
|
|
206
258
|
private readonly fetchImpl;
|
|
207
|
-
|
|
259
|
+
readonly pollIntervalMs: number;
|
|
208
260
|
private readonly retryDelayMs;
|
|
209
261
|
constructor(opts?: ConnectionOptions);
|
|
210
262
|
request<T>(method: string, path: string, opts?: RequestOptions): Promise<T>;
|
|
@@ -215,6 +267,8 @@ declare class HttpClient {
|
|
|
215
267
|
waitForOperation(op: Operation, timeoutMs?: number): Promise<Operation>;
|
|
216
268
|
}
|
|
217
269
|
|
|
270
|
+
/** The API's limit on `stdin`, in UTF-8 bytes. */
|
|
271
|
+
declare const MAX_STDIN_BYTES: number;
|
|
218
272
|
interface CommandOptions {
|
|
219
273
|
/** Working directory. Default: the server's default (HOME, `/data/home`). */
|
|
220
274
|
cwd?: string;
|
|
@@ -222,22 +276,23 @@ interface CommandOptions {
|
|
|
222
276
|
envs?: Record<string, string>;
|
|
223
277
|
/** Command timeout in ms (sent as whole seconds). Default: the server's default. */
|
|
224
278
|
timeoutMs?: number;
|
|
225
|
-
/** Text sent to the command's standard input. */
|
|
279
|
+
/** Text sent to the command's standard input, at most 1 MiB (UTF-8). */
|
|
226
280
|
stdin?: string;
|
|
227
281
|
/**
|
|
228
282
|
* Called with stdout once the command finished. Output is not streamed yet:
|
|
229
283
|
* the callback receives the whole stdout in one call.
|
|
230
284
|
*/
|
|
231
|
-
onStdout?: (data: string) =>
|
|
285
|
+
onStdout?: (data: string) => unknown;
|
|
232
286
|
/** Like `onStdout`, for stderr. */
|
|
233
|
-
onStderr?: (data: string) =>
|
|
234
|
-
/** Start the command detached (nohup) and return right away with its PID. */
|
|
287
|
+
onStderr?: (data: string) => unknown;
|
|
288
|
+
/** Start the command detached (nohup, in its own session) and return right away with its PID. */
|
|
235
289
|
background?: boolean;
|
|
236
290
|
}
|
|
237
291
|
/** A command started with `background: true`. */
|
|
238
292
|
interface CommandHandle {
|
|
293
|
+
/** PID of the command's shell, which leads the process group of everything it started. */
|
|
239
294
|
pid: number;
|
|
240
|
-
/** Sends SIGTERM to the process. Returns false if
|
|
295
|
+
/** Sends SIGTERM to the command and every process it started. Returns false if they had all exited. */
|
|
241
296
|
kill(): Promise<boolean>;
|
|
242
297
|
}
|
|
243
298
|
declare class Commands {
|
|
@@ -286,7 +341,10 @@ declare class Files {
|
|
|
286
341
|
read(path: string, opts: {
|
|
287
342
|
format: 'bytes';
|
|
288
343
|
}): Promise<Uint8Array>;
|
|
289
|
-
/**
|
|
344
|
+
/**
|
|
345
|
+
* Writes a file, creating parent directories. Replaces the file atomically (temp file + rename).
|
|
346
|
+
* Throws `is_a_directory` when `path` is a directory.
|
|
347
|
+
*/
|
|
290
348
|
write(path: string, data: string | Uint8Array): Promise<WriteInfo>;
|
|
291
349
|
/** Lists the entries of a directory (not recursive). */
|
|
292
350
|
list(path: string): Promise<EntryInfo[]>;
|
|
@@ -296,9 +354,11 @@ declare class Files {
|
|
|
296
354
|
exists(path: string): Promise<boolean>;
|
|
297
355
|
}
|
|
298
356
|
|
|
299
|
-
declare const DEFAULT_TEMPLATE = "
|
|
357
|
+
declare const DEFAULT_TEMPLATE = "agent-browser";
|
|
358
|
+
/** The default when a server does not offer `DEFAULT_TEMPLATE` (an older or self-hosted one). */
|
|
359
|
+
declare const FALLBACK_TEMPLATE = "universal";
|
|
300
360
|
interface SandboxOpts extends ConnectionOptions {
|
|
301
|
-
/** Machine name
|
|
361
|
+
/** Machine name: lowercase letters, digits and `-`. Default `sbx-<random>`. */
|
|
302
362
|
name?: string;
|
|
303
363
|
/** String labels stored with the sandbox; filter on them with `Sandbox.list({ metadata })`. */
|
|
304
364
|
metadata?: Record<string, string>;
|
|
@@ -313,7 +373,14 @@ interface SandboxOpts extends ConnectionOptions {
|
|
|
313
373
|
onTimeout?: OnTimeout;
|
|
314
374
|
/** Stop and archive after this many milliseconds, independent of the pause/kill timeout. */
|
|
315
375
|
archiveMs?: number;
|
|
316
|
-
/**
|
|
376
|
+
/**
|
|
377
|
+
* The server pauses the sandbox once it has been idle this long (no agent working, no terminal use,
|
|
378
|
+
* little CPU); the next command, file read or SSH sign-in resumes it. Sent as whole seconds, 2 min to
|
|
379
|
+
* 24 h. Default: 30 minutes. `0`: never, the sandbox stays on until paused or killed. Change it later
|
|
380
|
+
* with `setAutoSuspend()`.
|
|
381
|
+
*/
|
|
382
|
+
autoSuspendMs?: number;
|
|
383
|
+
/** vCPUs. Default: the template's. Services with fixed sizes (api.instabox.sh) refuse the size options. */
|
|
317
384
|
vcpus?: number;
|
|
318
385
|
/** Memory in MiB. Default: the template's. */
|
|
319
386
|
memMiB?: number;
|
|
@@ -321,6 +388,13 @@ interface SandboxOpts extends ConnectionOptions {
|
|
|
321
388
|
diskGiB?: number;
|
|
322
389
|
/** Root disk size in GiB; may only grow. */
|
|
323
390
|
rootDiskGiB?: number;
|
|
391
|
+
/**
|
|
392
|
+
* `false`: the sandbox never gets the account's Vault items (the secrets the dashboard's Vault page or
|
|
393
|
+
* `instabox vault set` keeps, written into every sandbox of the account at boot and resume). Pass it for
|
|
394
|
+
* sandboxes made for other people: anything running in a sandbox can read what the Vault writes into it.
|
|
395
|
+
* Default: the sandbox gets them. Cannot be turned on again later.
|
|
396
|
+
*/
|
|
397
|
+
vault?: boolean;
|
|
324
398
|
}
|
|
325
399
|
interface SandboxConnectOpts extends ConnectionOptions {
|
|
326
400
|
/** Resume the sandbox if it is paused (suspended) or stopped. Default true. */
|
|
@@ -340,12 +414,16 @@ interface SandboxInfo {
|
|
|
340
414
|
name: string;
|
|
341
415
|
/** String labels stored with the sandbox. */
|
|
342
416
|
metadata: Record<string, string>;
|
|
417
|
+
/** The sandbox gets the account's Vault items at boot and resume (`vault: false` at creation, or `disableVault()`, turns this off for good). */
|
|
418
|
+
vault: boolean;
|
|
343
419
|
/** Creation time of the machine. */
|
|
344
420
|
startedAt: Date;
|
|
345
421
|
/** When the server pauses or kills the sandbox (see `onTimeout`); undefined for no timeout. */
|
|
346
422
|
endAt?: Date;
|
|
347
423
|
archiveAt?: Date;
|
|
348
424
|
onTimeout: OnTimeout;
|
|
425
|
+
/** Idle time after which the server pauses the sandbox; undefined when it never does. */
|
|
426
|
+
autoSuspendMs?: number;
|
|
349
427
|
state: MachineState;
|
|
350
428
|
/** The raw machine object from the API. */
|
|
351
429
|
machine: Machine;
|
|
@@ -362,8 +440,12 @@ interface ForkOpts {
|
|
|
362
440
|
/** Timeout of the copy, as in `SandboxOpts.timeoutMs`. Default: none (the source's is not copied). */
|
|
363
441
|
timeoutMs?: number;
|
|
364
442
|
onTimeout?: OnTimeout;
|
|
443
|
+
/** Idle pause of the copy, as in `SandboxOpts.autoSuspendMs`. Default: 30 minutes (the source's is not copied); `0`: never. */
|
|
444
|
+
autoSuspendMs?: number;
|
|
365
445
|
/** Metadata of the copy. Default: the source's; `{}` for none. */
|
|
366
446
|
metadata?: Record<string, string>;
|
|
447
|
+
/** `false`: the copy never gets the account's Vault items (a copy of a sandbox without the Vault never does). */
|
|
448
|
+
vault?: boolean;
|
|
367
449
|
/**
|
|
368
450
|
* A fork needs a stopped source. When true (default), `fork()` stops the source first if needed
|
|
369
451
|
* (running processes end, `/data` is kept) and leaves it stopped; call `resume()` to start it again.
|
|
@@ -403,7 +485,10 @@ declare class Sandbox {
|
|
|
403
485
|
/**
|
|
404
486
|
* Creates a sandbox and waits until it is running.
|
|
405
487
|
* `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
|
|
488
|
+
* Template IDs take precedence over snapshot names. Default template: `agent-browser` (universal
|
|
489
|
+
* with a desktop and browser preinstalled, which the dashboard's Computer tab shows), or
|
|
490
|
+
* `universal` on a server that does not offer it. A snapshot that is still being saved is waited
|
|
491
|
+
* for (up to `operationTimeoutMs`).
|
|
407
492
|
*/
|
|
408
493
|
static create(opts?: SandboxOpts): Promise<Sandbox>;
|
|
409
494
|
static create(template: string, opts?: SandboxOpts): Promise<Sandbox>;
|
|
@@ -419,7 +504,11 @@ declare class Sandbox {
|
|
|
419
504
|
static getSnapshot(snapshotId: string, opts?: ConnectionOptions): Promise<Snapshot>;
|
|
420
505
|
/** Deletes a snapshot. Returns false if absent. Requires images:delete. */
|
|
421
506
|
static deleteSnapshot(snapshotId: string, opts?: ConnectionOptions): Promise<boolean>;
|
|
422
|
-
/**
|
|
507
|
+
/**
|
|
508
|
+
* Saves the sandbox's disks as a private snapshot. Requires images:write. The sandbox may be running;
|
|
509
|
+
* the snapshot is then returned with `status: 'pending'` and becomes `ready` once saved. For a stopped
|
|
510
|
+
* sandbox it waits first for a recent stop's upload to object storage (see `untilSynced`).
|
|
511
|
+
*/
|
|
423
512
|
createSnapshot(opts: CreateSnapshotOpts): Promise<Snapshot>;
|
|
424
513
|
/** Fetches the current state of the sandbox. */
|
|
425
514
|
getInfo(): Promise<SandboxInfo>;
|
|
@@ -430,8 +519,29 @@ declare class Sandbox {
|
|
|
430
519
|
setTimeout(timeoutMs: number, opts?: {
|
|
431
520
|
onTimeout?: OnTimeout;
|
|
432
521
|
}): Promise<void>;
|
|
522
|
+
/**
|
|
523
|
+
* Pauses the sandbox once it has been idle `idleMs` (whole seconds, 2 min to 24 h); 0 turns the idle
|
|
524
|
+
* pause off. Unlike a timeout the setting stays across pause and resume.
|
|
525
|
+
*/
|
|
526
|
+
setAutoSuspend(idleMs: number): Promise<void>;
|
|
433
527
|
/** Replaces the sandbox's metadata (`{}` clears it). */
|
|
434
528
|
setMetadata(metadata: Record<string, string>): Promise<void>;
|
|
529
|
+
/**
|
|
530
|
+
* What the Vault writes into this sandbox: whether it takes the Vault, the items that apply with its
|
|
531
|
+
* current metadata (names and paths, never values) and the last write. Requires machines:read.
|
|
532
|
+
* Throws `not_found` on a server without the Vault.
|
|
533
|
+
*/
|
|
534
|
+
vault(): Promise<MachineVault>;
|
|
535
|
+
/**
|
|
536
|
+
* Writes the account's current Vault items into the running sandbox now, the same write as after a boot,
|
|
537
|
+
* and returns its record (`error` set when the guest refused it). Requires machines:write.
|
|
538
|
+
*/
|
|
539
|
+
pushVault(): Promise<VaultApplied>;
|
|
540
|
+
/**
|
|
541
|
+
* Turns the Vault off for this sandbox, for good, in any state: its next boot, resume or push removes
|
|
542
|
+
* what the Vault wrote and nothing is written again. Requires machines:write.
|
|
543
|
+
*/
|
|
544
|
+
disableVault(): Promise<void>;
|
|
435
545
|
/** True if the sandbox is running (fetches fresh state). */
|
|
436
546
|
isRunning(): Promise<boolean>;
|
|
437
547
|
/** Snapshots memory and stops the sandbox (suspend). `resume()` or `Sandbox.connect()` brings it back. */
|
|
@@ -449,7 +559,8 @@ declare class Sandbox {
|
|
|
449
559
|
/**
|
|
450
560
|
* Issues a short-lived SSH certificate for `publicKey` (authorized_keys format).
|
|
451
561
|
* Connect with `ssh -p <port> -o CertificateFile=<cert> -i <key> <username>@<host>` after adding
|
|
452
|
-
* `knownHostsLine` to known_hosts. The sandbox must be running.
|
|
562
|
+
* `knownHostsLine` to known_hosts. The sandbox must be running. `ttlSeconds`: 1 to 86 400 (24 h);
|
|
563
|
+
* default: the server's (1 h).
|
|
453
564
|
*/
|
|
454
565
|
sshCredentials(publicKey: string, opts?: {
|
|
455
566
|
ttlSeconds?: number;
|
|
@@ -460,7 +571,14 @@ declare class Sandbox {
|
|
|
460
571
|
* Every state-dependent method calls this first, so it never decides from a stale cache.
|
|
461
572
|
*/
|
|
462
573
|
private settle;
|
|
574
|
+
/**
|
|
575
|
+
* Waits until a stopped sandbox's disks are in object storage (`storage.synced`). A stop returns
|
|
576
|
+
* once the host has the snapshot and uploads it after, so a fork or snapshot right after a stop
|
|
577
|
+
* was refused ("not uploaded to object storage"), which took long enough after a pause and resume
|
|
578
|
+
* to fail every time. Only a stopped sandbox is waited for; the server says what else is wrong.
|
|
579
|
+
*/
|
|
580
|
+
private untilSynced;
|
|
463
581
|
private mutate;
|
|
464
582
|
}
|
|
465
583
|
|
|
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 };
|
|
584
|
+
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, FALLBACK_TEMPLATE, Files, type ForkOpts, type HostTrust, InstaboxAuthError, InstaboxError, type InstaboxErrorInit, InstaboxQuotaError, InstaboxTimeoutError, MAX_FILE_BYTES, MAX_STDIN_BYTES, type Machine, type MachineList, type MachineSpec, type MachineState, type MachineVault, type MachineVaultItem, type OnTimeout, type Operation, Sandbox, type SandboxConnectOpts, type SandboxInfo, type SandboxListOpts, type SandboxOpts, type Snapshot, type SnapshotList, type SshCredentials, type Template, type TemplateRef, type VaultApplied, type VaultFile, type VaultKept, type WriteInfo };
|