API Reference

REST v1 overview, base URL, auth, idempotency, operations, errors, and the sandbox endpoint table for the Sandal API.


Sandal exposes one REST API. The TypeScript, Python and Go SDKs and the sandal CLI are generated from, and thin wrappers around, the same OpenAPI spec. If an SDK doesn't cover something, the REST API does.

Base URL and paths#

https://api.sandal.dev

Sandbox resources live under an organization and project:

/v1/organizations/{organizationId}/projects/{projectId}/...

Your organization id (org_...) and project id (project_...) are shown in the Console. Raw REST paths need them; the SDKs and the CLI resolve both from the API key, so SANDAL_API_KEY alone is enough there. Every response is JSON.

Authentication#

Send a project API key as a bearer token:

curl "https://api.sandal.dev/v1/organizations/$SANDAL_ORGANIZATION_ID/projects/$SANDAL_PROJECT_ID/sandboxes" \
  -H "Authorization: Bearer $SANDAL_API_KEY"

Create keys in the Console under API keys. A key is bound to one project and carries scopes; sandboxes need sandbox:read and sandbox:write. A request outside the key's scopes fails with 403 permission_denied; a missing, expired or revoked key fails with 401 auth_invalid. Never put the key in a URL.

Idempotency and request ids#

Every mutating request needs two headers:

  • Idempotency-Key: replaying the same key with the same body returns the original result ("replayed": true) instead of acting twice. Reusing a key with a different body returns 409 conflict with reason idempotency_conflict.
  • X-Request-Id: a correlation id for the request. The SDKs reuse the idempotency key when you don't set one.

Both accept [A-Za-z0-9][A-Za-z0-9_.:-]*, up to 256 characters; a UUID works.

Revisions#

Mutations carry the revision you last read, so concurrent writers can't silently overwrite each other:

  • exec, files, port exposures and snapshots take expectedSandboxRevision
  • lifecycle verbs (start, stop, pause, resume, archive, recover, fork, delete) take expectedRevision

Read the current value from GET .../sandboxes/{sandboxId} (revision). A stale value returns 409 conflict with reason revision_conflict; read again and retry.

Operations#

Lifecycle mutations (create, start, stop, archive, recover, fork, delete) return 202 Accepted with the sandbox and an operation:

{
  "sandbox": { "id": "sandbox.1845...", "state": "creating", "revision": 1, "...": "..." },
  "operation": { "id": "...", "sandboxId": "sandbox.1845...", "action": "create", "state": "planned", "...": "..." },
  "replayed": false
}

Poll the operation until state is succeeded or failed (failureCode says why):

curl "https://api.sandal.dev/v1/organizations/$SANDAL_ORGANIZATION_ID/projects/$SANDAL_PROJECT_ID/sandbox-operations/$OPERATION_ID" \
  -H "Authorization: Bearer $SANDAL_API_KEY"

The SDKs wrap this as sandboxes.waitForOperation / wait_for_operation / WaitForOperation.

Errors#

Error bodies share one shape: a code, a human-readable message, and extra fields per type.

{
  "_tag": "SandboxApiConflictError",
  "code": "conflict",
  "reason": "invalid_state",
  "message": "Sandbox archive requires a running Sandbox; start or resume it first."
}
StatuscodeExtra fields
400invalid_request
401auth_invalid
403permission_denied
404resource_not_found
409conflictreason
422capability_unavailablefeature (not enabled on this deployment or project)
429quota_exceededresource, limit, attempted, retryAfterMs
500internal_error

409 conflict reasons#

reasonMeaning
idempotency_conflictSame Idempotency-Key reused with a different request body
revision_conflictexpectedRevision / expectedSandboxRevision is stale
invalid_stateThe sandbox is in the wrong state for this action (e.g. archive on a stopped sandbox)
operation_activeAnother operation on this resource is still running; retry with the same idempotency key
stale_resultThe sandbox could not confirm current state yet (for example while it is still becoming ready); retry
identity_conflictThe request conflicts with the identity of an existing resource

429 quota resources#

resource is one of sandboxes, vcpus, memory_mib, disk_gib, network_attachments, template_builds, request_rate, desktop_recordings. In the private beta each project can hold 64 concurrent workloads, 256 vCPU and 512 GiB of memory (forks count; a fork needs room for parent and child). See Limits. Stopped sandboxes can still hold capacity; delete what you don't need.

Sandbox endpoints#

All paths below are relative to /v1/organizations/{organizationId}/projects/{projectId}.

Method + pathDescription
POST /sandboxesCreate a sandbox (202 + operation)
GET /sandboxesList sandboxes (limit, cursor, kind, state)
GET /sandboxes/{sandboxId}Get one sandbox, including state and revision
POST /sandboxes/{sandboxId}/start · /stop · /archive · /recover · /deleteLifecycle (202 + operation)
POST /sandboxes/{sandboxId}/forkFork into a new sandbox (202 + operation)
GET /sandbox-operations/{operationId}Poll an operation
POST /sandboxes/{sandboxId}/processesExec a command (?wait=true&waitTimeoutMs= to wait up to 20 s)
GET /sandboxes/{sandboxId}/processes/{processId}Process record, including exitCode
GET /sandboxes/{sandboxId}/processes/{processId}/eventsOutput events (afterSequence, limit, waitMs long poll)
POST /sandboxes/{sandboxId}/files/contentWrite a file (base64)
GET /sandboxes/{sandboxId}/files/downloadRead a file (path, offset, limit)
GET /sandboxes/{sandboxId}/filesList a directory
POST /sandboxes/{sandboxId}/port-exposuresExpose a port at an authenticated URL
GET /sandboxes/{sandboxId}/port-exposures/{exposureId}Poll an exposure until ready
POST /sandboxes/{sandboxId}/snapshotsCreate a snapshot
GET /sandboxes/{sandboxId}/snapshots · /snapshots/{snapshotId}List / get snapshots
POST /sandboxes/{sandboxId}/code/executionsRun code in a stateful interpreter context
GET /sandboxes/{sandboxId}/lifecycle-policy · POSTRead / change automatic stop, archive, delete
POST /sandboxes/{sandboxId}/keep-aliveRecord activity (restart the idle clock)
GET /sandbox-templates/{templateId}Published digest, profile and architecture of a template
GET /sandbox-capabilitiesFeatures and limits enabled for the project

The spec contains more (browser sessions, git, language servers, volumes, SSH, computer use, template builds, webhooks, devices, runners). Some of those are not yet qualified on the beta deployment and return 422 capability_unavailable or 404; GET /sandbox-capabilities (or sandal capabilities) tells you what your project has.

Examples#

Set these once:

export SANDAL_API_KEY=...                 # Console -> API keys
export SANDAL_ORGANIZATION_ID=org_...
export SANDAL_PROJECT_ID=project_...
BASE="https://api.sandal.dev/v1/organizations/$SANDAL_ORGANIZATION_ID/projects/$SANDAL_PROJECT_ID"

Create a sandbox#

KEY=$(uuidgen)
# one hour from now (GNU date; on macOS use: date -u -v+1H +%Y-%m-%dT%H:%M:%SZ)
EXPIRES=$(date -u -d '+1 hour' +%Y-%m-%dT%H:%M:%SZ)
curl -X POST "$BASE/sandboxes" \
  -H "Authorization: Bearer $SANDAL_API_KEY" \
  -H "Idempotency-Key: $KEY" \
  -H "X-Request-Id: $KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "kind": "virtual-machine",
    "profile": "enter-agent-linux",
    "templateId": "<template-id>",
    "templateDigest": "sha256:cea120929a1542e07611f7fcb6cc9f2ef70aa2a2f26a563997441d2c0cbda4fa",
    "size": "s",
    "architecture": "amd64",
    "name": "my-sandbox",
    "lifecycle": { "expiresAt": "'"$EXPIRES"'" }
  }'

kind, profile and lifecycle.expiresAt are required. The response is 202 with sandbox.id and operation.id; poll the operation until it succeeded (about 1.5-3.6 s at size s from the warm pool; 12-16 s cold at size m and larger).

Exec inside a sandbox#

REV=$(curl -s "$BASE/sandboxes/$SANDBOX_ID" -H "Authorization: Bearer $SANDAL_API_KEY" | jq .revision)
KEY=$(uuidgen)
curl -X POST "$BASE/sandboxes/$SANDBOX_ID/processes?wait=true&waitTimeoutMs=20000" \
  -H "Authorization: Bearer $SANDAL_API_KEY" \
  -H "Idempotency-Key: $KEY" \
  -H "X-Request-Id: $KEY" \
  -H "Content-Type: application/json" \
  -d "{\"command\": [\"python3\", \"-c\", \"print(6*7)\"], \"expectedSandboxRevision\": $REV}"

command is an argv array. The response has process, output events (each with base64 dataBase64), terminal, and nextSequence for resuming via GET .../processes/{processId}/events?afterSequence=.

Fork a sandbox#

REV=$(curl -s "$BASE/sandboxes/$SANDBOX_ID" -H "Authorization: Bearer $SANDAL_API_KEY" | jq .revision)
KEY=$(uuidgen)
curl -X POST "$BASE/sandboxes/$SANDBOX_ID/fork" \
  -H "Authorization: Bearer $SANDAL_API_KEY" \
  -H "Idempotency-Key: $KEY" \
  -H "X-Request-Id: $KEY" \
  -H "Content-Type: application/json" \
  -d "{\"expectedRevision\": $REV, \"name\": \"my-fork\"}"

The response is 202 with the new sandbox and an operation. Fork takes 10-15 s end to end today (disk only: running processes are not carried over).

Delete a sandbox#

Delete is a POST, not an HTTP DELETE:

REV=$(curl -s "$BASE/sandboxes/$SANDBOX_ID" -H "Authorization: Bearer $SANDAL_API_KEY" | jq .revision)
KEY=$(uuidgen)
curl -X POST "$BASE/sandboxes/$SANDBOX_ID/delete" \
  -H "Authorization: Bearer $SANDAL_API_KEY" \
  -H "Idempotency-Key: $KEY" \
  -H "X-Request-Id: $KEY" \
  -H "Content-Type: application/json" \
  -d "{\"expectedRevision\": $REV}"

Pagination#

List endpoints are cursor-paginated:

curl "$BASE/sandboxes?limit=50&cursor=$CURSOR" \
  -H "Authorization: Bearer $SANDAL_API_KEY"
{
  "sandboxes": [ ... ],
  "nextCursor": "..."
}

Pass nextCursor back as cursor to fetch the next page; it is null on the last page. Other lists use the same shape with their own array field (snapshots, entries, ...).

OpenAPI#

The full machine-readable spec (every path, parameter, request/response schema and error shape) is sandal-openapi-v0.1.0-beta.16.json. It is included in the private-beta SDK packages; request access at hello@sandal.dev. Use it to generate clients in languages we don't ship an SDK for, or to load into API tooling.