Sandboxes
TypeScript SDK
Every class and method in @quietrobot/sandboxes, and the request each one makes.
Note
The SDK (
@quietrobot/sandboxes0.1.0, Apache 2.0) isn't on npm yet. Each method below is one REST call, so you can use the REST API from any language today. A Python SDK and theqrcommand-line tool are built too, and aren't on PyPI yet.
The SDK has no dependencies and works anywhere fetch does: Node.js 18 or newer, Deno, Bun and edge runtimes.
Sandboxes (the client)
import { Sandboxes } from "@quietrobot/sandboxes";
const qr = new Sandboxes({
apiKey: process.env.QR_API_KEY, // default: QR_API_KEY
baseUrl: "https://www.quietrobot.ai/app", // default: QR_BASE_URL
fetch: globalThis.fetch, // optional, for tests or proxies
});| Method | Returns | Request |
|---|---|---|
create(options?) | Sandbox | POST /sandboxes |
get(id) | Sandbox | GET /sandboxes/{id} |
list(status?) | SandboxInfo[] | GET /sandboxes?status= |
execution(id) | Execution | GET /executions/{id} |
audit({ before?, limit?, action? }) | AuditEvent[] | GET /audit |
snapshots() | SnapshotInfo[] | GET /snapshots |
deleteSnapshot(id) | SnapshotInfo | DELETE /snapshots/{id} |
reservations() | Reservation[] | GET /reservations |
create options
| Option | Type | Notes |
|---|---|---|
name | string | Up to 80 characters. |
template | string | "base" (default). See templates. |
cpuClass | "standard" | "performance" | Default "standard". |
cpus | 1 | 2 | 4 | 8 | 16 | |
memoryMb | number | Multiple of 256. See sizes. |
timeoutSec | number | Lifetime. Default 600. |
region | string | For example "us-virginia" or "eu-frankfurt". |
egress | { mode?, allow? } | "deny" (default), "allowlist" or "open". |
env | Record<string, string> | Environment for every command. Names starting with QR_ are ignored. |
metadata | Record<string, string> | Your own labels, returned as is. |
snapshotId | string | Start with a snapshot's files. |
reservationId | string | Run on a reserved machine. |
pool | boolean | false always boots a fresh VM instead of taking a pre-started one. |
Sandbox
What create and get return. sbx.info holds the latest sandbox object; sbx.id is its id.
| Method | Returns | Request |
|---|---|---|
exec(cmd, options?) | Execution | POST /sandboxes/{id}/exec, then polls if held |
files.write(path, data) | { path, bytes } | PUT /sandboxes/{id}/files |
files.read(path) | Uint8Array | GET /sandboxes/{id}/files |
files.readText(path) | string | GET /sandboxes/{id}/files |
files.remove(path) | { path } | DELETE /sandboxes/{id}/files |
files.list(path?) | { path, entries } | GET /sandboxes/{id}/files/list |
setTimeout(timeoutSec) | SandboxInfo | POST /sandboxes/{id}/timeout |
pause() | SandboxInfo | POST /sandboxes/{id}/pause |
resume() | SandboxInfo | POST /sandboxes/{id}/resume |
snapshot(name?) | SnapshotInfo | POST /sandboxes/{id}/snapshots |
executions() | Execution[] | GET /sandboxes/{id}/executions |
audit() | AuditEvent[] | GET /sandboxes/{id}/audit |
refresh() | SandboxInfo | GET /sandboxes/{id} |
destroy() | SandboxInfo | DELETE /sandboxes/{id} |
files.write takes a string, Uint8Array or ArrayBuffer.
exec options
| Option | Default | Notes |
|---|---|---|
cwd | /home/sandbox | Absolute path to run in. |
env | Extra variables for this command. | |
timeoutMs | 60,000 | Up to 300,000. |
waitForApproval | true | Wait for a person when a rule holds the command. false returns the pending execution at once. |
approvalTimeoutMs | 30 minutes | How long to wait for that person. |
onPending | Called once with the execution when it's held. |
While waiting, exec polls GET /executions/{id} starting at once a second and slowing to once every 5 seconds.
Errors
Every failed request throws SandboxesError with status (HTTP status), code and message. See Errors for the codes.
| Class | When |
|---|---|
SandboxesError | Any error response. |
CommandDeniedError | exec waited and a person denied the command. Has execution. Extends SandboxesError with status 403 and code denied. |
If no one decides within approvalTimeoutMs, exec throws SandboxesError with code approval_timeout. The command stays held; a person can still decide later.
import { CommandDeniedError, Sandboxes, SandboxesError } from "@quietrobot/sandboxes";
try {
await sbx.exec("git push origin main");
} catch (e) {
if (e instanceof CommandDeniedError) console.log("A person said no:", e.execution.approval?.note);
else if (e instanceof SandboxesError && e.code === "approval_timeout") console.log("Still waiting");
else throw e;
}