@insforge/instabox-sdk 0.5.2 → 0.6.0
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 +59 -40
- package/dist/index.cjs +783 -82
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +227 -40
- package/dist/index.d.ts +227 -40
- package/dist/index.js +783 -82
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/skills/instabox/SKILL.md +21 -25
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@insforge/instabox-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "TypeScript SDK for instabox: create sandboxes on Firecracker dev machines, run commands, move files, pause, resume, snapshot and SSH in.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
package/skills/instabox/SKILL.md
CHANGED
|
@@ -16,14 +16,14 @@ export INSTABOX_API_URL=https://api.instabox.sh
|
|
|
16
16
|
|
|
17
17
|
Obtain keys from the dashboard's API Keys page or `instabox keys create`. If no key is configured, ask the user to configure one. Never print keys, commit them, or put them into metadata.
|
|
18
18
|
|
|
19
|
-
| Scope | Operations
|
|
20
|
-
| ----------------- |
|
|
21
|
-
| `machines:read` | List/get machines, templates and operations, a machine's Vault view
|
|
22
|
-
| `machines:write` | Create, start, stop, pause, resume,
|
|
23
|
-
| `machines:delete` | Delete machines
|
|
24
|
-
| `images:read` | List/get snapshots and resolve snapshot names
|
|
25
|
-
| `images:write` | Save a stopped machine as a snapshot
|
|
26
|
-
| `images:delete` | Delete snapshots
|
|
19
|
+
| Scope | Operations |
|
|
20
|
+
| ----------------- | ------------------------------------------------------------------- |
|
|
21
|
+
| `machines:read` | List/get machines, templates and operations, a machine's Vault view |
|
|
22
|
+
| `machines:write` | Create, start, stop, pause, resume, metadata, exec, SSH, Vault push |
|
|
23
|
+
| `machines:delete` | Delete machines |
|
|
24
|
+
| `images:read` | List/get snapshots and resolve snapshot names |
|
|
25
|
+
| `images:write` | Save a stopped machine as a snapshot |
|
|
26
|
+
| `images:delete` | Delete snapshots |
|
|
27
27
|
|
|
28
28
|
The current API calls snapshot scopes `images:*`. Write and delete imply read. Keys cannot manage keys or use admin routes. A `403 insufficient_scope` requires the relevant scope; do not retry it.
|
|
29
29
|
|
|
@@ -38,11 +38,7 @@ Runs on Node 18+, Bun, Deno and Cloudflare Workers. On Workers, `TypeError: Ille
|
|
|
38
38
|
```ts
|
|
39
39
|
import { Sandbox } from '@insforge/instabox-sdk'
|
|
40
40
|
|
|
41
|
-
const box = await Sandbox.create('
|
|
42
|
-
timeoutMs: 30 * 60_000,
|
|
43
|
-
onTimeout: 'kill',
|
|
44
|
-
metadata: { task: 'example' },
|
|
45
|
-
})
|
|
41
|
+
const box = await Sandbox.create('agent-browser', { metadata: { task: 'example' } })
|
|
46
42
|
try {
|
|
47
43
|
console.log((await box.commands.run('uname -a')).stdout)
|
|
48
44
|
await box.files.write('/data/home/proof.txt', 'hello')
|
|
@@ -54,23 +50,23 @@ try {
|
|
|
54
50
|
}
|
|
55
51
|
```
|
|
56
52
|
|
|
57
|
-
A new sandbox pauses itself after 30 idle minutes and resumes on the next command, file read or SSH sign-in. Pass another idle time as `autoSuspendMs` (or `setAutoSuspend(ms)` later); `autoSuspendMs: 0` means the sandbox runs until code calls `pause()`, `stop()` or `kill()`. Keep `sandboxId` for that, and reattach with `Sandbox.connect(id, { resume: false })` so attaching does not wake it. `pause()` keeps memory and processes; `stop()` ends processes and keeps disks; `kill()` deletes the sandbox and its disks.
|
|
53
|
+
A new sandbox pauses itself after 30 idle minutes and resumes on the next command, file read or SSH sign-in. Pass another idle time as `autoSuspendMs` (or `setAutoSuspend(ms)` later); `autoSuspendMs: 0` means the sandbox runs until code calls `pause()`, `stop()` or `kill()`. Keep `sandboxId` for that, and reattach with `Sandbox.connect(id, { resume: false })` so attaching does not wake it. `pause()` keeps memory and processes; `stop()` ends processes and keeps disks; `kill()` deletes the sandbox and its disks. A forgotten sandbox pauses itself once idle; kill it in a `finally` as the examples do. There is no lifetime timeout: `timeoutMs`, `onTimeout` and `setTimeout()` (SDK 0.5) throw `InstaboxError` code `retired_option`.
|
|
58
54
|
|
|
59
|
-
Connection options `{ apiKey, apiUrl }` override environment variables. `agent-browser` (universal plus a desktop and browser) is the default template; `universal` on a server without it. Create accepts a template ID, a private snapshot name, or a `sn_...` snapshot ID. Template IDs take precedence; duplicate snapshot names require an ID. There are no official snapshots. Template creation and snapshot-ID creation need only machine scopes; snapshot-name lookup also needs `images:read`.
|
|
55
|
+
Connection options `{ apiKey, apiUrl }` override environment variables. `agent-browser` (universal plus a desktop and browser) is the default template; `universal` on a server without it. The free plan creates from `agent-browser` (and `ci`) only; other templates need a paid plan (`403 template_not_allowed` on free). Create accepts a template ID, a private snapshot name, or a `sn_...` snapshot ID. Template IDs take precedence; duplicate snapshot names require an ID. There are no official snapshots. Template creation and snapshot-ID creation need only machine scopes; snapshot-name lookup also needs `images:read`.
|
|
60
56
|
|
|
61
57
|
Drive the desktop with `box.desktop`: `start()`, `open(url)`, `screenshot()` (PNG bytes), `click(x, y)`, `move`, `drag`, `scroll`, `type(text)`, `press('Enter' | ['ctrl', 'l'])`, `cursorPosition()`. `streamUrl({ viewOnly: true })` returns a link (also embeddable in an iframe) that shows the desktop to people without an account; its expiry stops new connections, and `revokeStreamUrls()` ends every link and disconnects open viewers.
|
|
62
58
|
|
|
63
59
|
Save and restore a private snapshot with the required snapshot scopes:
|
|
64
60
|
|
|
65
61
|
```ts
|
|
66
|
-
const source = await Sandbox.create('
|
|
62
|
+
const source = await Sandbox.create('agent-browser')
|
|
67
63
|
let saved: string | undefined
|
|
68
64
|
let restored: Sandbox | undefined
|
|
69
65
|
try {
|
|
70
66
|
await source.files.write('/data/home/proof.txt', 'persisted')
|
|
71
67
|
await source.stop()
|
|
72
68
|
saved = (await source.createSnapshot({ name: 'prepared-workspace' })).id
|
|
73
|
-
restored = await Sandbox.create(saved
|
|
69
|
+
restored = await Sandbox.create(saved)
|
|
74
70
|
console.log(await restored.files.read('/data/home/proof.txt'))
|
|
75
71
|
} finally {
|
|
76
72
|
try {
|
|
@@ -89,7 +85,7 @@ try {
|
|
|
89
85
|
|
|
90
86
|
The account's Vault (secrets a person set on the dashboard's Vault page or with `instabox vault set NAME`, `set-file PATH`, `import .env`) is written into every sandbox of the account at boot and resume: `env` items as environment variables of every login shell (so of `commands.run` and `instabox exec`), `file` items as files under HOME. An API key cannot read, create or change items; do not try, and never ask for a secret's value to put it somewhere else.
|
|
91
87
|
|
|
92
|
-
- A sandbox made for another person or tenant must be created with `vault: false` (`Sandbox.create('
|
|
88
|
+
- A sandbox made for another person or tenant must be created with `vault: false` (`Sandbox.create('agent-browser', { vault: false })`, `Sandbox.create(snapshot.id, { vault: false })`, `instabox create --no-vault`, REST `"vault": false`): anything running in it can read what the Vault writes. This is for good; `disableVault()` / `PATCH {"vault": false}` does the same to an existing sandbox.
|
|
93
89
|
- A sandbox for the account's own work takes the Vault by default. Before asking the person for a credential, check what is already there: `box.vault()` (`GET /v1/machines/{id}/vault`) lists the item names and the last write; in the sandbox, `env | grep NAME` or the file path.
|
|
94
90
|
- `box.pushVault()` (`POST /v1/machines/{id}/vault`, `instabox vault push <box>`) writes the current items into a running sandbox now; otherwise a changed item arrives at the next boot or resume (a changed `env` item reaches new shells only).
|
|
95
91
|
- An item's selector limits it to sandboxes whose metadata has those labels: create the sandbox with the metadata the person's items expect.
|
|
@@ -101,19 +97,19 @@ The account's Vault (secrets a person set on the dashboard's Vault page or with
|
|
|
101
97
|
```sh
|
|
102
98
|
curl -fsSL "$INSTABOX_API_URL/install.sh" | sh
|
|
103
99
|
instabox templates
|
|
104
|
-
instabox create --name dev --template
|
|
100
|
+
instabox create --name dev --template agent-browser
|
|
105
101
|
instabox exec dev -- uname -a
|
|
106
102
|
instabox ssh dev
|
|
107
103
|
instabox suspend dev
|
|
108
104
|
instabox resume dev
|
|
109
105
|
instabox rm dev
|
|
110
|
-
instabox create --name tenant --template
|
|
106
|
+
instabox create --name tenant --template agent-browser --no-vault # for someone else
|
|
111
107
|
instabox vault show dev; instabox vault push dev # what the Vault wrote; write it now
|
|
112
108
|
```
|
|
113
109
|
|
|
114
110
|
Use `instabox help` for the full command surface. With `INSTABOX_API_KEY` set, no interactive login is needed.
|
|
115
111
|
|
|
116
|
-
REST uses `X-API-Key` and the API origin above. Discover templates with `GET /v1/templates`; create with `POST /v1/machines` and `{ "name": "dev", "templateId": "
|
|
112
|
+
REST uses `X-API-Key` and the API origin above. Discover templates with `GET /v1/templates`; create with `POST /v1/machines` and `{ "name": "dev", "templateId": "agent-browser" }`. To restore, send `snapshotId` in place of `templateId`.
|
|
117
113
|
|
|
118
114
|
Lifecycle calls and PATCH need a fresh `Idempotency-Key`, reused only when retrying that same request. Lifecycle calls return an operation. Poll `GET /v1/operations/{id}?wait=25s` until `succeeded` or `failed`; report the operation error on failure. Exec returns its result directly and must not be retried automatically.
|
|
119
115
|
|
|
@@ -123,11 +119,11 @@ For SSH certificates, use `box.sshCredentials(publicKey)`. Use its returned host
|
|
|
123
119
|
|
|
124
120
|
## Limits and errors
|
|
125
121
|
|
|
126
|
-
- `CommandExitError` carries stdout, stderr, exitCode, timedOut and truncated.
|
|
127
|
-
- Files are limited to 10 MiB per read/write
|
|
128
|
-
- `
|
|
122
|
+
- `CommandExitError` carries stdout, stderr, exitCode, timedOut and truncated. With `onStdout` or `onStderr` the output is streamed to them as the command writes it (not capped); without them it is buffered and capped at 1 MiB per stream. stdin is capped at 1 MiB; commands may run for at most 600 seconds, and a timeout throws `CommandExitError` with `timedOut: true` and exit code 124. For longer commands use `background: true`: it returns `{ pid, jobId, kill(), wait({ onStdout }) }`; `wait` streams the job's log (stdout and stderr together) and resolves with its exit code, and `kill()` ends the command and everything it started. Pass `onStdout` to `wait()`, not to a background `run` (that throws `bad_request`). A sandbox without bash, util-linux `setsid` and GNU coreutils throws `background_unsupported`. The CLI's `instabox jobs logs <sandbox> <jobId> -f` follows the same job.
|
|
123
|
+
- Files are limited to 10 MiB per read/write; each moves in one HTTP request (a few seconds for 10 MiB).
|
|
124
|
+
- `files.read(path)` returns text only for valid UTF-8; a binary file (image, archive, compiled output) throws `InstaboxNotUtf8Error` (code `not_utf8`) instead of a string with U+FFFD. Read binaries with `files.read(path, { format: 'bytes' })` (exact `Uint8Array`).
|
|
125
|
+
- `InstaboxAuthError` covers 401/403 credential and access errors (a bad key, missing scope, `permission_denied`); `InstaboxQuotaError` covers quota, plan and billing limits (`template_not_allowed`, `spec_not_allowed`, `credit_exhausted` and the rest of `LIMIT_CODES`, whatever the status, and any 402) and 429, including the limit of 32 requests per user at once across all sandboxes (commands, file reads, desktop, port-forward and vault-push calls share it; a background command counts only while it starts, and its `wait()` while it waits); `InstaboxTimeoutError` covers request/operation deadlines; `InstaboxNotUtf8Error` (`not_utf8`) is a text read of a file that is not UTF-8. `InstaboxError` carries status, code, requestId and operationId.
|
|
129
126
|
- Inspect `GET /v1/usage` for account quotas. Sizes on `api.instabox.sh` are fixed (4 vCPU, 8 GiB, 16 GiB root, 20 GiB `/data`); do not pass `vcpus`, `memMiB`, `diskGiB` or `rootDiskGiB` there (`400 spec_not_allowed`). Sandbox names are lowercase letters, digits and `-`.
|
|
130
127
|
- Metadata and saved disks may contain plaintext. Do not save credentials into snapshots.
|
|
131
|
-
- Timeout is a one-shot deadline, not inactivity detection; resume does not reset it. Set a new timeout after resuming when needed.
|
|
132
128
|
|
|
133
129
|
See [the package README](../../README.md) for the full SDK reference.
|