quiet robotBook a call

Sandboxes

TypeScript SDK

Every class and method in @quietrobot/sandboxes, and the request each one makes.

View as Markdown

Sandboxes is in early access. It is free to try, some parts are still in testing, and details may change. Sign up free

Note

The SDK (@quietrobot/sandboxes 0.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 the qr command-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)

TypeScript
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
});
MethodReturnsRequest
create(options?)SandboxPOST /sandboxes
get(id)SandboxGET /sandboxes/{id}
list(status?)SandboxInfo[]GET /sandboxes?status=
execution(id)ExecutionGET /executions/{id}
audit({ before?, limit?, action? })AuditEvent[]GET /audit
snapshots()SnapshotInfo[]GET /snapshots
deleteSnapshot(id)SnapshotInfoDELETE /snapshots/{id}
reservations()Reservation[]GET /reservations

create options

OptionTypeNotes
namestringUp to 80 characters.
templatestring"base" (default). See templates.
cpuClass"standard" | "performance"Default "standard".
cpus1 | 2 | 4 | 8 | 16
memoryMbnumberMultiple of 256. See sizes.
timeoutSecnumberLifetime. Default 600.
regionstringFor example "us-virginia" or "eu-frankfurt".
egress{ mode?, allow? }"deny" (default), "allowlist" or "open".
envRecord<string, string>Environment for every command. Names starting with QR_ are ignored.
metadataRecord<string, string>Your own labels, returned as is.
snapshotIdstringStart with a snapshot's files.
reservationIdstringRun on a reserved machine.
poolbooleanfalse 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.

MethodReturnsRequest
exec(cmd, options?)ExecutionPOST /sandboxes/{id}/exec, then polls if held
files.write(path, data){ path, bytes }PUT /sandboxes/{id}/files
files.read(path)Uint8ArrayGET /sandboxes/{id}/files
files.readText(path)stringGET /sandboxes/{id}/files
files.remove(path){ path }DELETE /sandboxes/{id}/files
files.list(path?){ path, entries }GET /sandboxes/{id}/files/list
setTimeout(timeoutSec)SandboxInfoPOST /sandboxes/{id}/timeout
pause()SandboxInfoPOST /sandboxes/{id}/pause
resume()SandboxInfoPOST /sandboxes/{id}/resume
snapshot(name?)SnapshotInfoPOST /sandboxes/{id}/snapshots
executions()Execution[]GET /sandboxes/{id}/executions
audit()AuditEvent[]GET /sandboxes/{id}/audit
refresh()SandboxInfoGET /sandboxes/{id}
destroy()SandboxInfoDELETE /sandboxes/{id}

files.write takes a string, Uint8Array or ArrayBuffer.

exec options

OptionDefaultNotes
cwd/home/sandboxAbsolute path to run in.
envExtra variables for this command.
timeoutMs60,000Up to 300,000.
waitForApprovaltrueWait for a person when a rule holds the command. false returns the pending execution at once.
approvalTimeoutMs30 minutesHow long to wait for that person.
onPendingCalled 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.

ClassWhen
SandboxesErrorAny error response.
CommandDeniedErrorexec 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.

TypeScript
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;
}