ibk_...).
Install and authenticate
INSTABOX_API_KEY and INSTABOX_API_URL, or takes { apiKey, apiUrl } as options for
a key from your own secret store. Without a key, every call throws InstaboxAuthError
(missing_api_key) before sending a request. Over HTTP, send the key as X-API-Key or
Authorization: Bearer.
Running the examples
Running the examples
The examples use
import and top-level await. Save one as a .mjs file and run it with Node.js 18
or later, or set "type": "module" in your package.json for a .js file.So that a failed step does not leave a machine running, wrap the steps after create in try and
finally { await sbx.kill() }. Your app keeps the machine and deletes it when your user is done.Create a machine
Sandbox.create waits until the machine runs, so the script prints the new machine’s ID, m_....
agent-browser is the default template: Linux, a desktop, and a browser. Later, from another request:
Over HTTP, lifecycle calls (create, pause, resume, delete) return an operation. Poll it until
succeeded or failed before the next change to that machine. Lifecycle calls need an
Idempotency-Key header and answer 400 without one. Reuse a key only to retry the same request.Create over HTTP: defaults and refusals
Create over HTTP: defaults and refusals
POST /v1/machines takes {}, which creates an agent-browser machine named box- and 8 random hex
digits. An unknown templateId is 400, listing the templates your plan can create from. A body
field the API lacks is 400 unknown_field. For "template", the error asks: did you mean
"templateId"?Run a command and move files
42, and its exit code, 0. Then it prints the file it
wrote, print("hi"). To run a command without throwing on a non-zero exit, use sbx.commands.exec.
exec over HTTP
exec over HTTP
- Send
cmd(a shell string, run withbash -lc) orargv(a program and its arguments, run with no shell), not both. - It returns
stdout,stderr, andexitCodewhen the command exits. AftertimeoutSeconds(60 by default, at most 600), the command is killed. - With
Accept: text/event-stream(instabox exec --stream), it streams output as the command runs. To run a longer job detached, useinstabox exec --backgroundandinstabox jobs. - It takes no
Idempotency-Key, so a retry runs the command again. - When a disk of the machine is at least 90% full, or the command failed with
No space left on device, the result carries adiskWarning. Its fields aremount,usedPct,level,noSpace, andmessage, and it names the full disk and the fix:instabox resize <box> --disk <GiB>grows/data, live on a running machine.instabox execprints it on stderr.
Pause and resume the machine
true, because connect
resumes the machine.
Idle machines pause by themselves after minutes. To change that, call
sbx.setAutoSuspend(idleMs). sbx.stop() shuts the machine down and keeps /data. See
Lifecycle.
Delete the machine
true. The second prints false, because the machine is already gone.
Open an SSH session
sbx.sshCredentials(publicKey) takes your public key and returns a short-lived certificate. Over HTTP,
send your public key to POST /v1/machines/{id}/connections, with an Idempotency-Key. It returns the
certificate and the host CA. See SSH.
Full example
Full example
The example prints the
ssh command to run.Drive the desktop
machines:write that can reach the machine, including a workspace key, opens its desktop
over GET /v1/machines/{id}/vnc. That route is a WebSocket carrying the VNC (RFB) stream. A share link
(sbx.desktop.streamUrl()) is for the machine’s creator only. See Desktop for links,
embedding, and an agent loop.
Open the VNC WebSocket from Node.js
Open the VNC WebSocket from Node.js
Read usage and metrics per customer
Tag each machine with your customer when you create it, then read usage by that tag:getUsage covers the current UTC month by default and counts running time only, not paused or stopped
time. A Sandbox object has the same calls: sbx.getUsage() and sbx.getMetrics().
Sandbox.usage() returns account counts, storage, and limits.
Handle errors
Calls throwInstaboxError with status and code, such as not_found or quota_exceeded. A
missing or bad key throws InstaboxAuthError. See Errors.
Use the CLI with a key
WithINSTABOX_API_KEY set, the CLI needs no login:
Reference
SDK calls and their HTTP endpoints
SDK calls and their HTTP endpoints
SDK reference
Every call, by task: snapshots, labels, files and more.
API reference
Every endpoint an API key calls.
Python SDK
The same calls from Python:
pip install instabox-sdk.