Sandboxes API

Create and manage managed sandboxes: VMs on platform engines, or on your own, that run belt remote start and connect back as an ordinary remote. Use a sandbox's remote_id with the Remotes and Exec runs APIs the same way as a machine you registered yourself.

Requires API key scopes sandboxes:read (list, get) and sandboxes:write (create, start, stop, delete). The standard preset includes both. The key a box holds has the remote preset's scopes only, so a box cannot create sandboxes.

Sandboxes are open to every workspace whose paying account made a purchase in the last 30 days. Without one, create and start answer 402 purchase_required. When the workspace's feature:sandboxes entitlement is set to enabled: false, they answer 403 feature_not_available, detail sandboxes are turned off for this workspace. Plan limits cap running sandboxes and their vCPUs. See Sandbox limits and pricing for limits, prices and every error.

→ Remotes API · Exec runs API · Managed sandboxes · Quickstart · Inside a sandbox


Concepts

TermDescription
SandboxA workspace record for one managed VM. The API places it on an engine with room, mints a key for the box, and handles start, stop, restarts and billing.
RemoteCreated with the sandbox and kept across restarts. The box registers as this remote.
GenerationGoes up on every start, including automatic restarts. Each generation mints a new box key; the remote id stays the same. The writable disk is kept on the engine the box last ran on (see disk_kept), unless it is given up or you start on a fresh disk.

Sandboxes run on engines that report the sandboxes engine capability: the platform's by default, or your workspace's own. See Where a sandbox runs.

Inside the box, INFERENCE_API_URL points at the API. Credentials reach the box as bound secrets: the box holds placeholders (infsh_ph_...), and the engine's egress gateway puts the real value on requests to allowed hosts only. The box key is bound to the API host for the sandbox's remote. When the sandbox has inference.sh access, INFERENCE_API_KEY is a placeholder for a delegated sandbox token holding its api_scopes. Secret values never enter the box.


Lifecycle

statusMeaning
pendingWants to run; waiting for worker capacity, credit, or a restart backoff
startingSent to the engine
runningThe VM is up (its remote may still be connecting)
stoppingStop sent
stoppedBox stopped; the record and remote remain
failedGave up; see status_reason
desired_stateSet by
runningCreate, POST /sandboxes/{id}/start, or an automatic restart
stoppedPOST /sandboxes/{id}/stop, or idle auto-stop
deletedDELETE /sandboxes/{id}

status_reason values include no capacity, out of credit, the engine went away, waiting for the engine that keeps its disk, and reasons such as stopped after 15 minutes idle from idle auto-stop. When the kept disk is given up, the reason starts with its disk was lost:. The platform gives it up when the box fails to start on the keeping engine 3 times in a row (its disk was lost: the box did not start on it 3 times (last: …), so it starts on a new disk), when that engine stays offline or full past the capacity wait, when it has no room for the box, or when you start with fresh_disk. When the engine itself drops a kept disk (seven days, or its host ran short of disk), no reason is written: disk_kept turns false and the next start gets a new disk. A box that ends on its own, or whose remote stays disconnected for 3 minutes, restarts after 5 s, 30 s, then 2 min, at most 3 times in 10 minutes; after that it is failed.


Billing

A sandbox is billed per second for its vCPUs and memory, at the engine's resource prices, for the time it is healthy: its remote connected and heartbeating. Time the remote is away (no heartbeat for a minute) or disconnected is not billed. Disk is not billed. At start the owner's balance holds an hour of the sandbox's price; each hour, and at stop, the healthy time is charged as one sandbox usage debit.

With no balance, a new generation does not start (status_reason out of credit). A running box whose next hourly hold is refused is stopped with the same reason. Prices and an example: Pricing.


Where a sandbox runs

infra on create says whose engines the sandbox may be placed on. It is fixed for the sandbox's lifetime.

infraPlaced onPrice
cloud (default)Platform enginesThe engine's resource prices
privateYour workspace's own engines that report sandboxesFree
private_firstYour own engines when one has room, platform engines otherwiseFree on yours, the engine's prices on the platform's
  • Your engines only take your sandboxes. A sandbox is never placed on another workspace's engine.
  • No balance needed on your own engine. With no balance, a private sandbox starts, and a private_first one waits for room on your engines.
  • private needs an engine online at create. With none of your engines online and hosting sandboxes, create answers 400 validation_error. If the engine goes offline later, the sandbox stays pending with status_reason no engine online until it is back.
  • Limits are the same. Plan limits and the purchase condition apply to sandboxes on your own engines.
  • Forks and snapshots follow the engine. A fork runs where its source does. A sandbox made from a snapshot that one engine alone keeps starts on that engine: when that engine is yours, infra defaults to private, and cloud is refused with validation_error; when it is the platform's, private is refused.

Setting up an engine to host sandboxes: Using private engines — Sandboxes on private.


Create sandbox

POST /sandboxes

Requires sandboxes:write. Creates the sandbox and its remote, with desired_state running. A server with no box image configured answers 409 sandboxes are not set up on this server (no SANDBOX_IMAGE).

FieldTypeDescription
namestringDisplay name
vcpusintegerDefault 2. Max: see Sizes
memory_mibintegerDefault 4096. Max: see Sizes
disk_mibintegerDefault 10240. Max: see Sizes
idle_timeout_secondsintegerOptional. Stops the running box this long after last activity. Omitted defaults to 900 (15 minutes). 0 disables idle auto-stop. Otherwise 60–2_592_000 (30 days).
infrastringOptional. cloud (default), private or private_first. See Where a sandbox runs
from_snapshot_idstringOptional. Start on a copy of a ready snapshot's disk. See Create a sandbox from a snapshot
api_scopesstring[]Optional. inference.sh access for the box: scopes with sandbox: true on GET /scopes (reads, apps:execute, files:write, apps:write). Any other scope is refused with validation_error. Copied onto the sandbox for its lifetime, cut to what the caller can hand on. Omitted: the box holds only its remote scopes. Sandboxes created by an agent's sandbox_create tool use the agent version's api_scopes instead of this field.
bash
1curl -X POST https://api.inference.sh/sandboxes \2  -H "Authorization: Bearer inf_your_key" \3  -H "Content-Type: application/json" \4  -d '{"name":"dev-box"}'

Returns the sandbox.


List sandboxes

GET /sandboxes or POST /sandboxes/list

Requires sandboxes:read. Cursor-paginated like other list routes: cursor, direction and limit as query parameters on GET, or in the POST body with filters and sort.


Get sandbox

GET /sandboxes/{id}

Requires sandboxes:read.


Update sandbox

PATCH /sandboxes/{id}

Requires sandboxes:write. Today the body may only change idle_timeout_seconds (same rules as create). The change counts as activity and resets the idle clock. Other fields are left as they are; an empty body or a body with no supported field answers validation error nothing to update: idle_timeout_seconds is the field a sandbox changes.

bash
1curl -X PATCH https://api.inference.sh/sandboxes/sbx_xxx \2  -H "Authorization: Bearer inf_your_key" \3  -H "Content-Type: application/json" \4  -d '{"idle_timeout_seconds":7200}'

Returns the updated sandbox.


Keep sandbox active

POST /sandboxes/{id}/activity

Requires sandboxes:write. Records that the sandbox is still in use, as dispatching an exec run on its remote would. Updates last_activity_at and resets the idle auto-stop clock. Use it when work inside the box does not go through the API but you still want the VM to stay up (for example a long-lived process with nobody connected).

Returns the updated sandbox.


Start sandbox

POST /sandboxes/{id}/start

Requires sandboxes:write. Sets desired_state to running. A stopped or failed sandbox goes back to pending. When disk_kept is true, the next generation starts on the engine that keeps the sandbox's disk and reuses that writable disk; otherwise it gets a new empty disk (for example after seven days, when the engine dropped the disk, you passed fresh_disk, or the platform gave the disk up). A start asked for while stopping runs when the stop finishes.

Optional body:

FieldTypeDescription
fresh_diskbooleanWhen true on a stopped sandbox, give up the kept disk and start the next generation on a new empty disk on whatever engine has room. Answers 409 conflict if the sandbox is not stopped (stop the sandbox before starting it on a new disk).
bash
1curl -X POST https://api.inference.sh/sandboxes/sbx_xxx/start \2  -H "Authorization: Bearer inf_your_key" \3  -H "Content-Type: application/json" \4  -d '{"fresh_disk":true}'

Sandbox files

On a running sandbox, list, import, export, or delete files on its disk through the API. Each call runs a short command on the box's remote (the sandbox must be running and the remote connected). File bytes move between the box and platform file storage over short-lived transfer URLs inside the box, not through the request body. These routes require sandboxes:write and count as idle activity.

Import and export hold the HTTP request until the transfer finishes (like POST /remotes/{id}/execs?wait=N); list and delete typically finish within about a minute.

List directory

GET /sandboxes/{id}/files?path={absolute_path}

Returns up to 10_000 SandboxFileEntry objects for one directory. path must be absolute and clean (for example /home/user/project).

FieldTypeDescription
namestringEntry name in the directory
kindstringfile, dir, link, or other
sizeintegerSize in bytes (0 for directories)
modestringPermission bits (octal)
modified_atstringLast change (RFC3339), when known

Delete file

DELETE /sandboxes/{id}/files?path={absolute_path}

Removes a file or symlink at path. Directories cannot be deleted through this route.

Import onto the box

POST /sandboxes/{id}/files/import

Body:

FieldTypeRequiredDescription
pathstringYesAbsolute path to write on the box
file_idstringYesPlatform file to copy (upload first with POST /files; the key must be allowed to read that file)

Returns SandboxFileTransferDTO with path and file (the source file metadata).

Export from the box

POST /sandboxes/{id}/files/export

Body:

FieldTypeRequiredDescription
pathstringYesAbsolute path to a regular file on the box

Creates a new platform file in your workspace (files:write for storage) and returns SandboxFileTransferDTO with path, file, and a short-lived download_url to fetch the bytes.

bash
1# List, then export a report from a running sandbox2curl "https://api.inference.sh/sandboxes/sbx_xxx/files?path=/home/user" \3  -H "Authorization: Bearer inf_your_key"45curl -X POST https://api.inference.sh/sandboxes/sbx_xxx/files/export \6  -H "Authorization: Bearer inf_your_key" \7  -H "Content-Type: application/json" \8  -d '{"path":"/home/user/report.md"}'

Common errors: 404 when the sandbox or path does not exist; 409 conflict when the sandbox is not running; validation when path is not absolute or the wrong kind (for example a directory where a file is required).


Snapshots and forks

A snapshot is a copy of a stopped sandbox's kept disk. It holds the disk only, not memory or running processes. It is kept on the engine that took it until you delete it, and sandboxes made from it start on that engine. Snapshotting or forking a running sandbox, or one whose disk is no longer kept, answers 409 conflict (stop it first).

Create snapshot

POST /sandboxes/{id}/snapshots

Requires sandboxes:write. Body (optional): {"name": "..."}. Returns the snapshot with status pending; it becomes ready when the engine has copied the disk, or failed with status_reason.

List, get and delete snapshots

GET /sandboxes/snapshots, GET /sandboxes/snapshots/{id} (requires sandboxes:read), DELETE /sandboxes/snapshots/{id} (requires sandboxes:write).

FieldTypeDescription
id, namestringSnapshot id and name
sandbox_idstringThe sandbox it was taken of
image, vcpus, memory_mib, disk_mibThe source's image and size at the snapshot. A sandbox made from it runs that image, at least that size
bytesintegerWhat the copy holds on the engine
statusstringpending, ready or failed
status_reasonstringWhy it failed
ready_atstringWhen it became ready

Ready snapshots count toward the plan's sandbox_snapshots (see Plan limits).

Create a sandbox from a snapshot

Pass from_snapshot_id (a ready snapshot) to Create sandbox. It starts on a copy of the snapshot's disk with the snapshot's image. Sizes left out take the snapshot's; the disk is never smaller than the snapshot's.

Fork sandbox

POST /sandboxes/{id}/fork

Requires sandboxes:write. Snapshots the stopped sandbox, then makes count new sandboxes from it. Each fork is its own sandbox with its own remote, box key and billing. Starting the source afterwards changes none of them.

FieldTypeDescription
countintegerOptional. Default 1, max 20
namestringOptional. Forks are named name-1 … name-N (name alone for one). Default: the source's name plus -fork
idle_timeout_secondsintegerOptional. As in Create sandbox; default the source's
keep_snapshotbooleanOptional. Keep the fork's snapshot as one of the workspace's. Default false: it is deleted once every fork has started or failed

Response: {"sandboxes": [...], "snapshot_id": "..."}. When only some forks could be made, the ones made are returned with error saying why the rest were not.

bash
1curl -X POST https://api.inference.sh/sandboxes/$SANDBOX_ID/fork \2  -H "Authorization: Bearer $INFERENCE_API_KEY" \3  -H "Content-Type: application/json" \4  -d '{"count":3,"name":"try"}'

Ports

Open a TCP port inside a running sandbox on its own HTTPS URL. belt sandbox ports open|list|close does the same.

Open port

POST /sandboxes/{id}/ports

Requires sandboxes:write.

FieldTypeDescription
portintegerPort inside the box, 1–65535
publicbooleanOptional. True answers anyone with the URL. Default false: the URL carries a token, shown only in this response; a browser is asked for it once

Returns {"port", "public", "url", "created_at"}.

List and close ports

GET /sandboxes/{id}/ports (requires sandboxes:read) returns {"ports": [...]}. Private ports are listed without their token. DELETE /sandboxes/{id}/ports/{port} (requires sandboxes:write) closes one.


Tunnel

GET /sandboxes/{id}/tunnel?port=N

Requires sandboxes:write. A WebSocket whose binary messages are the bytes of a TCP stream to port N in the running sandbox, both ways. belt sandbox tunnel <sandbox> <port> pipes it to stdin and stdout, so it works as ssh's ProxyCommand (the box needs sshd and your key):

bash
1ssh -o ProxyCommand="belt sandbox tunnel dev 22" user@dev

Terminal

GET /sandboxes/{id}/terminal?cols=&rows=

Requires sandboxes:write. A shell on a PTY of the running sandbox, over a WebSocket. Binary messages are keystrokes in and output out. Text messages are {"type":"resize","cols":N,"rows":N} in and {"type":"exit","code":N,"error":"..."} out, last. belt sandbox ssh <sandbox> opens one; it needs no sshd or key.


Stop sandbox

POST /sandboxes/{id}/stop

Requires sandboxes:write. Stops the VM and keeps its writable disk on the engine it ran on (disk_kept becomes true). The sandbox and its remote stay, so you can start it again and pick up files on that disk. After seven days stopped, or sooner if the engine host runs short of disk, the engine may drop the disk and disk_kept becomes false.


Delete sandbox

DELETE /sandboxes/{id}

Requires sandboxes:write. Stops a live box, then removes the sandbox and its remote.


Idle auto-stop

A running sandbox whose idle_timeout_seconds is greater than zero is stopped automatically when it has gone that long without API-visible use. Use includes:

  • dispatching or finishing an exec run on its remote_id
  • sandbox file list, import, export, or delete
  • harness session events on that remote
  • creating or changing the sandbox (POST /sandboxes, PATCH /sandboxes/{id}, keep-alive)
  • the box starting for its current generation
  • the box's own traffic to or from hosts other than the API, on engines that report it (not every engine does yet; on one that does not, only the uses above count)

Other work inside the VM does not count. A process left running unattended that reaches nothing outside is still stopped when the idle period ends. While an exec run on the remote is pending or running, the sandbox is not idle; the clock restarts when the last such run ends.

In agent chat, a remote_exec call waiting on the person's approval also holds idle stop while its card is pending, unexpired, and at most one hour old, when the card names that sandbox (its remote id, sandbox id, or name). An answered or expired card does not hold.

Idle stop is the same as an owner stop: desired_state becomes stopped, the VM is shut down, and the writable disk is kept when the engine supports it (see Stop sandbox). If the engine does not report that a stop would keep the disk (disk_kept / disk_keepable), the platform waits longer: that box is idle-stopped only after the larger of its idle_timeout_seconds and 24 hours, with status_reason idle past 24 h; this box's disk could not be kept. A sandbox with idle_timeout_seconds 0 is never idle-stopped.

last_activity_at on the sandbox is when that use last happened (or the box last started, whichever is later). idle_timeout_seconds is the configured window; 0 turns auto-stop off.


Sandbox fields

FieldTypeDescription
idstringSandbox id
user_id, team_idstringOwner
namestringDisplay name
imagestringBox image the platform boots
vcpus, memory_mib, disk_mibintegerSize
infrastringcloud, private or private_first: whose engines it may be placed on
desired_statestringrunning, stopped or deleted
statusstringSee Lifecycle
status_reasonstringWhy it is pending or failed
generationintegerStarts so far, restarts included
engine_id, worker_idstringPlacement of the current generation; empty while pending or stopped
remote_idstringThe remote the box connects as
started_at, stopped_atstringTimestamps, when set
disk_keptbooleanWhile stopped, the engine the sandbox last ran on holds this generation's writable disk for the next start there
disk_kept_untilstringWhen a stopped sandbox's kept disk expires (stopped_at plus seven days). Omitted while running or when disk_kept is false. The engine may drop the disk sooner
idle_timeout_secondsintegerConfigured idle auto-stop window in seconds; 0 means never
last_activity_atstringWhen the sandbox was last used through the API, or its box last started, whichever is later. Drives idle auto-stop
api_scopesstring[]API scopes the box's token holds beyond its remote, copied at create from the request or the agent (empty when none were granted). Fixed for the sandbox's lifetime; agent changes apply only to new sandboxes

SDKs

Neither SDK has a client.sandboxes namespace; call the routes above. Generated types include SandboxDTO (idle_timeout_seconds, last_activity_at, api_scopes), CreateSandboxRequest (api_scopes), UpdateSandboxRequest, StartSandboxRequest, the SandboxStatus and SandboxDesiredState values, SandboxFileEntry, SandboxFileImportRequest, SandboxFileExportRequest, SandboxFileTransferDTO, EngineCapabilitySandboxes and ResourceFeatureSandboxes (@inferencesh/sdk and inferencesh Python package releases that include INF-1209; sandbox file routes ship with the API branches that add them). Sandbox access ships with INF-1292 (CreateSandboxRequest.api_scopes, AgentVersionDTO.api_scopes).

we use cookies

we use cookies to ensure you get the best experience on our website. for more information on how we use cookies, please see our cookie policy.

by clicking "accept", you agree to our use of cookies.
learn more.