API reference
Every HTTP endpoint for sandboxes, commands, files, templates, services, secrets, volumes, tenants, events and nodes.
Each /v1 request must have the header Authorization: Bearer <key>.
Spawnbox keeps only the SHA-256 hash of each key. An error response has
this format: {"error": {"code", "message", "request_id", "retryable"}}.
Errors
| Code | HTTP status | Retryable | Meaning |
|---|---|---|---|
invalid_request |
400 | No | A field is missing or wrong. |
unauthorized |
401 | No | The key is missing, wrong or revoked. |
forbidden |
403 | No | The key does not have the scope for this call. |
not_found |
404 | No | The sandbox, template or other resource does not exist. |
conflict |
409 | No | The resource is not in a state that allows this call, or the name is already used. |
protected_env |
409 | No | A snapshot would show env values of the sandbox. |
build_failed |
409 | No | A build that the sandbox needs could not be made. The same error is given for 5 minutes. |
quota_exceeded |
429 | Yes | A tenant quota is full. Try again after other sandboxes end. |
no_capacity |
503 | Yes | No host has room. The response has Retry-After: 30. |
node_unreachable |
503 | Yes | The host of the sandbox cannot be reached. |
volume_unavailable |
503 | Yes | The only copy of a volume is on a host that cannot be reached. |
rebuilding |
503 | Yes | A build that the sandbox needs is being made. |
sandbox_cold |
503 | Yes | A worker stopped the sandbox, and the primary starts it again. |
stale_route |
409 | Yes | Forward listener only: the sandbox moved or started again on another host. |
sandbox_paused |
503 | No | Forward listener only: the sandbox is paused and X-Spawnbox-Wake: never was set. |
wake_busy |
503 | Yes | Forward listener only: the host wakes too many sandboxes now. The response has Retry-After: 5. |
too_many_requests |
503 | Yes | Forward listener only: the sandbox has too many requests in flight. The response has Retry-After: 1. |
not_ready |
503 | Yes | Forward listener only: the service on the port is not healthy after 30 s. |
upstream_timeout |
504 | No | Forward listener only: the wake or the app took too long. |
upstream_unreachable |
502 | No | Forward listener only: nothing answers on the port in the sandbox. |
draining |
503 | Yes | Forward and preview requests: the sandbox is drained. |
generation_conflict |
409 | No | An endpoint switch named a generation that the endpoint is not at. The message has the current generation and target. |
internal |
500 | Yes | An unexpected error. The server log has the cause with the request_id. |
retryable in the response has the same value. Repeat a retryable call
after a short wait, with backoff.
Sandbox states
| State | Meaning | Next states |
|---|---|---|
starting |
The VM starts, for a create, a fork or a cold start. | running; failed if the start fails; deleted if it is deleted meanwhile; cold for a persistent sandbox |
running |
The VM runs. | paused, deleted; cold (persistent) or failed/deleted (ephemeral) when the VM is lost |
paused |
Memory and disk are saved in <data-dir>/paused/<id>, and the VM is stopped. |
running at a resume; deleted; cold (persistent) or failed (ephemeral) if the files cannot be used |
cold |
Persistent only. No VM and no saved memory. The start record (template build, env, secrets, network rules, volumes, services, ports) is kept. | starting at the next exec, file, terminal, clone, preview or resume call; deleted |
failed |
The sandbox could not start or lost its VM. It ends. | None |
deleted |
The sandbox was deleted, expired or lost. It ends. | None |
failed and deleted are final. These events show the changes:
| Change | Event | Reason |
|---|---|---|
| A create, fork or cold start ends | sandbox.created, sandbox.forked, sandbox.cold_started |
|
| Pause and resume | sandbox.paused, sandbox.resumed |
memory_pressure for a pause to free memory |
| An ephemeral sandbox loses its VM, or a server restart finds it running | sandbox.lost |
The state is failed or deleted. |
| The timeout ends | sandbox.expired |
|
A persistent sandbox becomes cold |
sandbox.cold |
server_restarted, shutdown (the server stopped before it could pause), vm_exited, pages_lost, pause_failed, froze_while_saving, resume_failed, guest_too_old, paused_files_missing, capacity (no room for its idle pause), start_unfinished, gone_from_node, node_reported |
| The primary fences a lost host, or a standby takes over | node.fenced, then sandbox.cold for each persistent sandbox of the host |
fenced with proof (operator, autoscaler, self_fence), or failover |
| A host stops its copy of a persistent sandbox | sandbox.fenced |
self_fenced or lease_lost (the host fenced itself), stale_generation (a newer copy exists), resume_fenced |
| A cold start uses a new build | sandbox.rebuilt |
missing, outdated, guest_too_old |
| A move to another host | sandbox.migrated |
Each cold start adds 1 to generation. A host stops a copy of a sandbox
from an older generation. Refer to Fence lost hosts.
A template build is queued, building, ready or failed. A ready
build becomes outdated when the kernel, base disk or runtime of the host
changes, and removed when a newer build replaces it or its template is
deleted. The files of outdated and removed builds are deleted.
Sandboxes
POST /v1/sandboxescreates a sandbox. Fields:template(defaultbase),timeout_s,idle_pause_s,env,labels,egress,secrets,volumes,persistent,services. Org keys can also sendtenant."persistent": truekeeps the sandbox until it is deleted. Do not sendtimeout_s.idle_pause_smust be more than 0 (default 600). On a fleet, the primary runs it, or a worker with--persistent-placement any. Refer to Keep a sandbox until you delete it.- The create response has
timings_msandstarted_from. The value ofstarted_fromiswarm_poolorbuild. - For a token or password that the sandbox sends in an HTTP header, use a
secret with
env, notenv. The sandbox then sees only a placeholder, and the value never enters the VM. Refer to Secrets. - Responses, events and logs never show env values.
- Each host adds up the
memory_mibof its running sandboxes. A create, fork or resume that goes over--memory-overcommit-pctof the host memory (default 150) gives503 no_capacitywithRetry-After: 30. A primary first tries the other hosts. Paused sandboxes do not count. - When free host memory drops below
--memory-pressure-pct(default 10) percent, or processes wait for memory that share of the time, the host pauses the sandbox with no running call that was used least recently, one at a time, and refuses creates and resumes with503 no_capacityuntil memory is fine again. Thesandbox.pausedevent has the reasonmemory_pressure. The next call resumes the sandbox as usual. - A Firecracker guest gives the pages it frees back to the host, so a sandbox uses only the memory it needs now. Templates built before this are rebuilt once.
GET /v1/sandboxeslists sandboxes. Org keys can add?tenant=.GET /v1/sandboxes/{id}gets one sandbox. It haspersistent,generation(1, plus 1 for each cold start),cold_startsandlast_cold_start_at. It never shows env values. A persistent sandbox has noexpires_at.- States:
starting,running,paused,cold,deleted,failed. Only persistent sandboxes becomecold. DELETE /v1/sandboxes/{id}deletes a sandbox. Acoldsandbox, or one that is starting again, is deleted at once. A start that ends after the delete stops its VM.- Spawnbox deletes a sandbox when its
timeout_sends. The maximum is--max-timeout-s. Time in the paused state is not counted. POST /v1/sandboxes/{id}:pausesaves the memory and disk in<data-dir>/paused/<id>and stops the VM.POST /v1/sandboxes/{id}:resumestarts the VM again. For acoldsandbox, it boots a new VM from the template build.- A cold start is given 120 seconds. Calls that come during a start wait
for it. If it fails or takes longer, the sandbox stays
coldand the next call tries again. - If the sandbox is already in the requested state, pause and resume do nothing.
- A paused sandbox shows
"state": "paused"andpaused_at. - Paused sandboxes stay after a server restart. Spawnbox deletes them
after
--paused-retention-s(default 7 days). Persistent sandboxes are not deleted. - Spawnbox encrypts the env of paused and persistent sandboxes on disk
with
--secrets-key-file. The env of the sandbox and of all its services is one ChaCha20-Poly1305 value, bound to the tenant and the sandbox ID. A value cannot be moved to another variable, service or sandbox. At start, Spawnbox encrypts env that an earlier version kept in another form. On SQLite, the first start after the upgrade also compacts the database file, to clear the plain copies. - If
secrets.keycannot read the stored env of a sandbox, the server does not start. Usually the key is not the one that encrypted it; put back the right key. With--allow-unreadable-envthe server starts, and leaves those sandboxes and their files as they are, so a later start with the right key resumes them. This helps only when the key reads everything else:secrets.keyalso encrypts the egress CA key, the stored secrets and, with Postgres, the files that primaries share. With a different key, the server still stops at those. Use the flag when the key is right but the env of some sandboxes cannot be read, for example rows that were damaged or copied from another installation. - Memory files and disks are not encrypted. Put
<data-dir>on an encrypted disk;spawnbox doctorwarns when it is not. - On Firecracker, a pause writes only the memory that changed since the sandbox was started or resumed. Spawnbox then merges it with the earlier memory in the background; a resume or a move waits for that merge. The first pause after a fork, a failed pause or a lazy (UFFD) restore writes all the memory. On the test server a full pause took approximately 0.7 s, and up to 12 s while earlier pauses were still being written.
POST /v1/sandboxes/{id}:forkstarts copies of a running sandbox on its host. Field:count, 1 to 16 (default 1).- The response is
201withsandboxes(the copies that started) andfailed(the number that did not start). - Each copy gets the memory, processes and files of the sandbox. It also gets its template, labels, env, secrets, network rules and the time that remains before its timeout.
- Each copy gets its own ID, hostname and random numbers. Its env is encrypted again for its own ID.
- Each copy counts against the quotas of the tenant.
- On the test server, 10 copies take approximately 0.7 s.
- The response is
POST /v1/sandboxes/{id}:snapshotsaves a running sandbox as a new template. Field:name.- The response is
201withtemplate,buildandspec. - The template is in the tenant of the sandbox. Its
envis the env of its template. Secrets are not saved. Add them again when you create a sandbox from the template. - A sandbox created with
env, or with a service that hasenv, gives409 protected_env, because the template would show the values. Use secrets for these values, or put them in the template spec. - The template has a
snapshotfield. You cannot rebuild the template. - Without a build store, sandboxes from the template start only on the host of the original sandbox. With a build store, a host with the same fingerprint and CPU model can get the files from the store.
- On the test server, a snapshot takes approximately 0.4 s.
- The response is
- Fork and snapshot stop the sandbox for the time of the save. They do not operate on a paused sandbox or on a sandbox with volumes.
Commands
POST /v1/sandboxes/{id}/execruns a command. Fields:cmd,cwd,env,user,timeout_s,stdin(maximum 1 MiB).- The JSON response has these fields:
stdoutandstderr, maximum 1 MiB each. Thestdout_truncatedandstderr_truncatedflags show if output was cut.exit_code,signalandtimed_out.duration_msandexec_id.
- With the header
Accept: text/event-stream, the response is a stream ofstdout,stderrandexitevents. If you close the stream, Spawnbox stops the command. - The request ends when the command ends. A background process that the command started can continue.
- Environment variables come from the template, then the sandbox, then the command. A later value replaces an earlier value.
Files
GET /v1/sandboxes/{id}/files?path=gets the contents of a file, or a JSON list for a directory.PUTwrites the request body to the file. Spawnbox creates the parent directories. It replaces the file only after it receives the full body.DELETEdeletes a file. To delete a directory, addrecursive=true.- A relative path starts at
/workspace. - Spawnbox does file operations as
user, unless you setuser=. Usual file permissions apply.
Terminals
GET /v1/sandboxes/{id}/pty?cols=&rows=&user=&cwd=&cmd=opens a WebSocket. It runsbash -l, orcmd, on a real terminal.- Binary frames carry terminal data in the two directions.
- To change the terminal size, send the text frame
{"type":"resize","cols","rows"}. - At the end, the server sends
{"type":"exit","exit_code","signal","duration_ms"}. - If you close the WebSocket, Spawnbox stops the shell.
- A browser can use a session token with the
terminalaudience instead of an API key: addsession_token=<token>to the query.
Browser session tokens
POST /v1/sandboxes/{id}/session-tokensmakes a token for one sandbox. Fields:audience(required):terminalorpreview.port: the published port that apreviewtoken opens. It is required forpreview, and not allowed forterminal.ttl_s: 1 to 900, default 900.
- The response has
tokenandexpires_at. The key must havesandboxes:write. A missing or badaudienceorportgives400 invalid_request. - The token is a JWT (HS256) with an
audclaim. Aterminaltoken opens only the terminal of that sandbox. Apreviewtoken opens only theprivatepreview URL of that port. A token does not work on other API calls. - The token stops at
expires_at, or when the key that made it is revoked. - Each new token records a
sandbox.session_token_createdevent, with itsaudience. - Spawnbox signs tokens with
<data-dir>/session.key. The primary sends this key to the workers. If you delete the file, all tokens stop.
Git
POST /v1/sandboxes/{id}/git:cloneclones a repository. Fields:url(https://orhttp://),path(default/workspace/<repo>),branch,depth,user,timeout_s.- The response has
path,commit,branchandduration_ms. - A
git_httpssecret on the sandbox gives access to private repositories. The token does not go into the sandbox.
Templates
POST /v1/templatescreates a template and starts a build. Fields:name.setup: commands that run as root, with network access.warmup: commands that run asuserimmediately before the snapshot. Background processes that they start continue in each sandbox.env.resources:vcpus,memory_mib,disk_gib.min_warm: the minimum number of warm VMs that each host keeps for this template, 0 to 16. The default is 0. Refer to Warm pools.base: a container image to start from, for examplenode:22-bookworm-slim. If you do not set it, the template starts from the Debian base. Refer to Start a template from a container image.registry_secrets: names of held secrets that Spawnbox uses only to getbase. A maximum of 4.
- The response is
202with the template and its build. GET /v1/templateslists templates.GETandDELETE /v1/templates/{name}get and delete one template.GET /v1/templates/{name}/builds/{build_id}gets the state, the error and the end of the build log.- You cannot change or delete the
basetemplate. - If you save a template again, Spawnbox starts a new build. Until the new
build is ready, sandboxes use the last ready build. If you change only
min_warm, Spawnbox does not start a new build. - If a template has no ready build, a create request gives
409. - Builds stay after a restart. Spawnbox builds again only when the kernel,
base disk, Firecracker version or
--disk-io-enginechanges. - Spawnbox runs a maximum of
--max-buildsbuilds at the same time.
Services
servicesinPOST /v1/sandboxesis a list of up to 8 services. Each has these fields:name: 1 to 63 ofa-z,0-9and-. It cannot start with-. Each name must be different.command: the program and its arguments. It cannot be empty.cwd(optional): an absolute path.env(optional): it cannot set the CA variables, such asSSL_CERT_FILE, or the variable of a secret of the sandbox.port(optional): 1 to 65535. Each port must be different.access(optional, needsport):private(default),tokenorpublic.health(optional, needsport):{"http": "/path"}or{"tcp": true}, withinterval_s(1 to 3600, default 10) andfailures(1 to 100, default 3).restart(optional):always(default) oron-failure.
- A wrong value gives
400 invalid_argument. A template without support for services gives409 conflict. GET /v1/sandboxes/{id}/servicesgives the state of each service:{"services": [{"name", "state", "pid", "restarts", "last_exit", "started_at"}]}.stateisstarting(until the first good health check),healthy,unhealthy,backoff(it waits to start again) orstopped.last_exitis{"code": 1},{"signal": 9}ornull.
POST /v1/sandboxes/{id}/services/{name}:restartstops a service and starts it again. The response is204. An unknown name gives404.GET /v1/sandboxes/{id}/services/{name}/logsgives the last 1 MiB of output as text. With?follow=true, the response is a stream ofoutputevents ({"text": "..."}) that continues with new output.- A stop sends
SIGTERMto the process group of the service, andSIGKILLafter 5 s. - These calls resume a paused or
coldsandbox, and count as activity. The work of a service in the VM does not keep the sandbox awake. - Spawnbox never shows the env values of a service. It encrypts the services of paused and persistent sandboxes on disk, in one value with the env of the sandbox.
- A fork copies the services and their processes. A snapshot template does not keep the list of services.
Preview URLs
POST /v1/sandboxes/{id}/portspublishes a port and gives its URL. Fields:port,access,ttl_s.GETlists the published ports.DELETE /v1/sandboxes/{id}/ports/{port}removes a published port.accesshas four values:token(default): the URL contains a token. The token stops afterttl_s(default 24 hours). At the first visit, it becomes a cookie.public: all persons with the URL can open it.private: the request must have the API key inAuthorization, or apreviewsession token for the port. Add the token to the URL as?spawnbox_session=<token>. At the first visit, it becomes a cookie. Spawnbox removes this cookie before the request goes to the app.gateway: the port has no preview URL. Only the forward listener can reach it.
- For each
access, Spawnbox removes these from a request before it goes to the app: thespawnbox_sessionandspawnbox_previewcookies, thespawnbox_sessionquery parameter, and anAuthorizationheader with a Spawnbox API key (Bearer sbx_...) or a session token that this install made. Onpublicandtokenports, otherAuthorizationvalues go to the app, so an app can use its own logins. Onprivateports, Spawnbox removes allAuthorizationvalues. - Spawnbox serves previews on
--preview-listenat--preview-url. It finds the sandbox from the host name. - HTTP/1.1 and WebSockets are supported.
- A request to the port of a service waits up to 30 s until the service
is healthy. Then it gives
503.
Forward requests from a gateway
Use the forward listener when your own HTTP gateway or load balancer sends traffic to sandbox ports. The gateway owns the host names, TLS for users and its own logins. Spawnbox wakes the sandbox and sends the request to the port.
-
Start it with
--forward-listen ADDR. Add--forward-tls-certand--forward-tls-keyfor TLS. Put the listener on a private network. Only your gateway must reach it. -
Make a key with only the
sandboxes:forwardscope for the gateway. This key cannot call the other APIs. A tenant key reaches only the sandboxes of its tenant. A revoked key stops working within 5 s. -
Publish the port first, with
POST /v1/sandboxes/{id}/ports. Useaccess: gatewayif the port must not have a preview URL. The listener forwards to a published port of eachaccess. -
The gateway sends the original request, with these headers:
Header Required Meaning X-Spawnbox-KeyYes The API key X-Spawnbox-TargetYes sbx_ID:PORT, orendpoint:NAMEfor an endpoint of the key’s tenant (defaultfor an org key)X-Spawnbox-WakeNo any(default) resumes a paused sandbox and starts a cold one.pausedonly resumes.neverwakes nothing.X-Spawnbox-Timeout-MsNo How long to wait for the response headers of the app. Default 60000, at most --forward-max-response-s. -
Spawnbox removes all
X-Spawnbox-*headers before the request goes to the app, and from the response of the app. Other headers, the path, the query and the body go to the app without change. -
The response has
X-Spawnbox-SandboxandX-Spawnbox-Generation. The generation goes up each time the sandbox starts on a host. A request to an endpoint also hasX-Spawnbox-Endpoint-Generation. -
If Spawnbox refuses the request, the body is a normal error and the response has
X-Spawnbox-Errorwith the code. A response without this header comes from the app. -
Limits:
--forward-max-wakes(default 8): wakes that run at once on a host. A request waits up to--forward-wake-queue-s(default 10) for a slot, then gets503 wake_busy. Requests for a sandbox that another request already wakes wait for that wake and take no slot.--forward-max-in-flight(default 1024): requests and WebSockets in flight for one sandbox. More get503 too_many_requests.- A wake can take up to 60 s. Then the request gets
504 upstream_timeout. - A request to the port of a service waits up to 30 s until the service
is healthy. Then it gives
503 not_ready. After a wake, a request to a port without a service waits up to 30 s until the port takes a connection.
-
HTTP/1.1 and WebSockets are supported.
-
In a fleet, the forward listener runs on the primary and on edges (with the same flags). It sends each request to the host of the sandbox. If the sandbox moved, the request is sent again once, when its body is at most 1 MiB. Edges send requests to an endpoint to the primary.
Port readiness
GET /v1/sandboxes/{id}/ports/{port}/ready tells whether a port takes
traffic:
{ "ready": false, "generation": 3, "state": "running", "reason": "service \"web\" on port 8000 is not healthy" }
- The port of a service is ready when the service is
healthy. Another published port is ready when it takes a TCP connection in the sandbox. - Without
wait_s, the call does not wake the sandbox. A sandbox that is not running, a port that is not published and a draining sandbox are not ready. - With
?wait_s=N(at most 120), the call wakes the sandbox and waits up toNseconds for the port to be ready. - The key needs
sandboxes:read.
Drain a sandbox
A drain takes a sandbox out of traffic without cutting the requests that it serves.
POST /v1/sandboxes/{id}:drainwithtimeout_s(1 to 3600, default 30) andthen(noneby default,pauseordelete). The response is202with the sandbox.- New forwarded and preview requests get
503 drainingat once. A draining sandbox that is paused does not wake for them. - When no forwarded or preview request or WebSocket is left, or at the
timeout, Spawnbox does
then. A pause or delete ends the requests that are left. - Commands, files, terminals and other API calls continue to operate.
- The sandbox stays out of traffic until
POST /v1/sandboxes/{id}:undrainor an endpoint switches to it, also afterthen. An undrain before the timeout stops the drain. GET /v1/sandboxes/{id}showsdrainwithstarted_at,deadline,in_flightandthenwhile the sandbox is drained.- Events:
sandbox.drain_started, andsandbox.drainedwithin_flight,closed(requests that the pause or delete ended) andthen. - The drain is kept in the memory of the host that runs the sandbox. If that host restarts, the drain ends.
Endpoints
An endpoint is a stable name for one sandbox port. To replace a sandbox,
switch the endpoint to the new one. Gateways send requests to
X-Spawnbox-Target: endpoint:NAME.
-
POST /v1/endpointswithname,sandboxandport. The endpoint is in the tenant of the sandbox. A name is 1 to 63 ofa-z,0-9and-, unique in its tenant. A new endpoint hasgeneration1. -
GET /v1/endpointsandGET /v1/endpoints/{name}show the target, thegenerationand thetarget_state. Org keys add?tenant=for an endpoint that is not indefault. -
DELETE /v1/endpoints/{name}removes the endpoint, not its target. -
PUT /v1/endpoints/{name}switches it:{ "sandbox": "sbx_NEW", "port": 8000, "if_generation": 4, "ready_wait_s": 60, "previous": { "drain_s": 30, "then": "pause" } }if_generationis required. The switch happens only if the endpoint is at this generation. Else the response is409 generation_conflict. Of two switches from the same generation, one wins.- The switch ends a drain of the new target, so you can switch back to a target that an earlier switch drained.
ready_wait_s(0 to 300, default 60): Spawnbox wakes the new target and waits until its port is ready. If it is not ready in time, or its port is not published, the response is503 not_readyand the endpoint does not change.0skips the check. The key needssandboxes:readfor this.previous: after the switch, the old target drains fordrain_s(default 30), then doesthen(defaultpause). Ifpreviousis not given, these defaults apply.nullleaves the old target alone.- The drain starts
--endpoint-propagation-s(default 2) after the switch, so requests that read the endpoint just before the switch still reach the old target. If an endpoint of the tenant targets the old sandbox again by then, it does not drain. A request to an endpoint that getsdrainingreads the endpoint again and is sent once more, when its body is at most 1 MiB. - The response has the endpoint with its new
generation, andpreviouswith the old target.
-
Each response through an endpoint has
X-Spawnbox-Endpoint-Generation, so you can see which generation served it. -
Events:
endpoint.created,endpoint.switched,endpoint.deleted. -
Endpoints are kept in the database of the primary and are in backups.
Network access (egress)
-
Each TCP connection from a sandbox goes through the egress proxy. Spawnbox records each connection.
-
Spawnbox always blocks these addresses:
- private and link-local addresses, which include cloud metadata
- loopback addresses
- the addresses of the host
- port 25 (SMTP)
-
A policy has this format:
{"mode": "allow_all" | "allowlist" | "deny_all", "allow": [...], "deny": [...]}. A pattern is a host name or*.example.com.allowlistchecks the TLS SNI or the HTTPHostname. It allows only ports 80 and 443.denyis checked by name too: the TLS SNI, the HTTPHostname or the DNS query. Thus, when any policy has adenylist,allow_allrefuses a TCP connection without a name on any port, for example to a bare address or TLS without SNI. It also drops UDP (except DNS) and ICMP. Without adenylist,allow_allallows these. An address written as a name, such asHost: 93.184.215.14or0x5db8d70e, counts as no name.denyblocks names, not addresses. Spawnbox does not compare the address that an allowed name resolves to with the addresses of denied names. A sandbox that can use a name whose DNS it controls, such as a wildcard DNS service that answers1-2-3-4.examplewith1.2.3.4, can reach the address of a denied host. Thus, adenylist stops mistakes and casual use, not a determined program. Useallowlistwhen that matters.- A name check sees only the name that the client sends in clear text.
A server that hosts many names, such as a CDN, can serve a denied
name behind an allowed one (domain fronting or TLS Encrypted Client
Hello). Use
allowlistwhen that matters. deny_allalso blocks DNS.
-
Each DNS query from a sandbox goes to the DNS forwarder of Spawnbox, for all DNS server addresses. The forwarder sends the query to
--dnsand records the name, the type, the result and the addresses.- When the policy does not allow a name, the answer is
REFUSED.
- When the policy does not allow a name, the answer is
-
Optional speed limits, in megabits per second, from 1 to 100000:
max_egress_mbps: the data that the sandbox sends.max_ingress_mbps: the data that the sandbox receives.
For example:
{"mode": "allow_all", "max_egress_mbps": 20, "max_ingress_mbps": 100}. The limits also apply after a resume. -
Spawnbox applies three policies:
--egress-policyof the server, theegressof the tenant and theegressof the sandbox. The strictest policy wins. For speed limits, the lowest limit wins.
Secrets
-
POST /v1/secretssaves a secret. Fields:name,type(http_headerorgit_https),value,allowed_hosts,env,header,format,username. -
GET,PATCHandDELETE /v1/secrets/{name}get, change and delete a secret. They never show the value. -
Spawnbox encrypts each value with ChaCha20-Poly1305. The key is in
<data-dir>/secrets.key, or in--secrets-key-file. -
Use a secret for each value that a sandbox sends in an HTTP header. With
env, the sandbox gets a placeholder in that variable, and the proxy puts the value in the request. Code in the sandbox cannot read or leak the value.CAUTION: Make a backup copy of
secrets.key. Without this file, you cannot read your secrets. -
For HTTPS requests to
allowed_hosts, the proxy puts the value in the header of the secret. The default header isAuthorization: Bearer.git_httpsuses Basic authentication. -
After a
PATCH, the next request uses the new value. -
A
PATCHthat adds toallowed_hostsor changesheaderorformatmust also sendvalue. Without it, the response is400 value_required, so a key that can change a secret cannot send its stored value to a new host. APATCHthat only removes hosts does not needvalue. -
The
secret.updatedandsecret.rotatedevents showallowed_hosts. When the hosts change, they also showprevious_allowed_hosts. They never show the value. -
Sandboxes trust the CA of the proxy.
SSL_CERT_FILE,NODE_EXTRA_CA_CERTS,REQUESTS_CA_BUNDLEandCURL_CA_BUNDLEpoint to the system certificate bundle.
Volumes
POST /v1/volumescreates a volume. Fields:name,size_gib(1 to 1024, default 10),tenant. A name has 1 to 63 characters:a-z,0-9and-. It cannot start with-.GET /v1/volumeslists volumes.GET /v1/volumes/{name}gets one volume. The response showssize_gib,backend,nodeandmounts: the sandboxes that use the volume.DELETE /v1/volumes/{name}deletes a volume and its data. If a sandbox uses the volume, the response is409. Delete the sandbox first.- To mount volumes, add
volumestoPOST /v1/sandboxes. Each item hasvolume,pathandread_only(defaultfalse). pathis an absolute path, for example/data. It cannot be/, or in/proc,/sys,/dev,/runor/spawn. Two paths cannot be one in the other.- Spawnbox makes the disk of a volume when a sandbox mounts it the first time. The disk uses space on the host only for the data in it.
- Usage shows the full
size_gibof each volume as disk use.
Tenants and keys
-
POST /v1/tenantscreates a tenant. Fields:id,name,quotas,egress,isolation. -
isolationisany(default) ormicrovm-only. Withmicrovm-only, the sandboxes of the tenant run only on Firecracker hosts. Refer to Firecracker or gVisor. -
GET /v1/tenantslists tenants.GET,PATCHandDELETE /v1/tenants/{id}get, change and delete one tenant.GETalso shows the current usage. -
The
defaulttenant always exists. -
You cannot delete a tenant that has sandboxes, templates or secrets. The response is
409. -
When you delete a tenant, Spawnbox cancels its keys.
-
There are two types of keys:
- Org keys (
sbx_org_...) can access all tenants. Older keys (sbk_...) are org keys. - Tenant keys (
sbx_tn_...) can access only their tenant. For other tenants, the response is404.
- Org keys (
-
POST /v1/keyscreates a key. Fields:tenant,scopes,name. Spawnbox shows the key only in this response. -
GET /v1/keyslists keys.DELETE /v1/keys/{id}cancels a key. -
Scopes:
sandboxes:read,sandboxes:write,sandboxes:forward,templates:write,secrets:write,tenants:admin(only org keys),audit:read,usage:read. A key without a scope list gets all the scopes that its type allows. -
A template or secret is for all tenants, or only for one tenant (
?tenant=). If two have the same name, the tenant’s own one wins. -
Quotas. The value
nullmeans no limit.Quota Default for a new tenant running_sandboxes20 running_vcpus40 running_memory_mib80 GiB max_session_s24 hours max_paused_retention_s7 days monthly_egress_bytesNo limit snapshot_storage_gibNo limit volume_storage_gibNo limit persistent_sandboxes0 The
defaulttenant has no limits, exceptpersistent_sandboxes.persistent_sandboxescounts persistent sandboxes in each state until they are deleted. If a request goes over a quota, the response is429 quota_exceeded.
Events
- You can send the header
X-Spawnbox-Step: <id>with each request, for example the ID of a tool call of your agent. You can also send a W3Ctraceparentheader. - The events from the request then have
step_idandtrace_id. Each event also hastenant,sandboxandactor. - Event types:
sandbox.created(withforked_fromfor a copy),.paused,.resumed,.forked,.snapshotted,.expired,.killed,.lost,.cold(withreason),.cold_started(withgeneration,buildandduration_ms),.rebuilt(withfrom_build,to_buildandreason),.fenced(withreasonandgeneration: a host stopped its copy),.migrated,.session_token_creatednode.joined,.up,.down,.draining,.drained,.undrained,.retiring,.retired,.removed,.fenced(withnodeandreason), primary onlyexec.started,exec.finished(with the last 64 KiB of output)pty.opened,pty.closedservice.started(withpid),service.exited(withexit),service.unhealthy(withfailures),service.restarted(withrestartsand thereasonexit,unhealthyorrequest). Each hasname.file.written(with the SHA-256 hash),file.deletedport.published,port.unpublishednet.connection,net.blockednet.dns(withname,type,verdict,rcode,answersandduration_ms)secret.injected(without the value)volume.created,volume.deletedsandbox.drain_started,sandbox.drainedendpoint.created,endpoint.switched,endpoint.deleted- changes to tenants, keys, secrets and templates, such as
template.savedandtemplate.deleted autoscale.requested,.done,.failed(primary only)
GET /v1/eventsandGET /v1/sandboxes/{id}/eventsget events. These are the filters:tenant,sandbox,step_id,type,since,until. The typeexec.*gets all theexecevents.- Use
limit(maximum 1000) andcursorto get more pages. follow=truestreams new events as server-sent events. After a disconnection, sendLast-Event-IDto continue.- The key must have the scope
audit:read. --otlp-endpointalso sends the events to OpenTelemetry as OTLP/HTTP log records.--otlp-endpointalso sends traces. Each create and each command is one trace. A create has the spansfetch_build,volumes,claim,restoreandfixups. A command has the spansopenandstart. On a primary, the spansandbox.placecontains onenodespan for each host that it tries.- If a request has a
traceparentheader, its trace contains the Spawnbox spans. The events of the request have the sametrace_id. - Spawnbox keeps events for
--events-retention-s(default 7 days).
Warm pools
A warm VM is a sandbox that Spawnbox restored before a request came. Its vCPUs are paused. A create takes a warm VM, starts its vCPUs and gives it a new clock, random seed and hostname.
- Spawnbox keeps a pool for each template build and network mode. The
network mode comes from the egress policies:
allow_all,allowlistordeny_all. - The target size of a pool is the number of creates in the last 30
seconds. The
basepool for the server’s egress policy has a minimum of--warm-pool-min. A template withmin_warmhas that minimum. A pool with no creates and no minimum falls to zero. - The
min_warmpool of a template uses the egress policy of the template’s tenant (allow_allfor org-wide templates). A sandbox with a narrower egress policy uses a different pool. - In a fleet, each host keeps
min_warmwarm VMs. - Warm VMs use a maximum of
--warm-pool-memory-pctof the host memory. They do not use the last--max-buildsfree slots. If a create or resume has no free slot, Spawnbox stops a warm VM. - Warm VMs are not counted in quotas or usage. Spawnbox counts them when a create takes them.
GET /v1/warm-poolsshows each pool:template,build,network,ready,filling,target,hitsandmisses. The key must have the scopetenants:admin.
Nodes
These calls operate only on a primary. The key must have the scope
tenants:admin.
| Call | Function |
|---|---|
POST /v1/nodes/tokens |
Make a join token. Optional body: {"ttl_s": 3600}, from 60 to 604800. The response has token, expires_at and ca_sha256. |
GET /v1/nodes |
List the workers and edges that are not removed |
GET /v1/nodes/autoscale |
Get the load, the workers in each state and the autoscaler requests. Refer to Add and remove workers automatically. |
GET /v1/nodes/{id} |
Get one worker or edge |
DELETE /v1/nodes/{id} |
Remove a worker or an edge. The sandboxes of a worker are marked deleted. |
POST /v1/nodes/{id}:drain |
Put no new sandboxes on the worker. You cannot drain an edge. With the body {"migrate":true}, also move its sandboxes and volumes to other hosts: persistent sandboxes become cold and start again on other hosts. Gives 202 when it moves sandboxes, with drain_pass set to started, or to already_running when a pass already runs, in which case it starts nothing. Call it again to retry what did not move. |
POST /v1/nodes/{id}:undrain |
Put new sandboxes on the worker again. Gives 409 if the worker retires. |
POST /v1/nodes/{id}:retire |
Retire the worker before you stop its machine. Optional body: {"migrate":true,"reason":"..."}. Gives 202. Refer to Retire a worker safely. |
POST /v1/nodes/{id}:fenced |
Tell the primary that the host of a down or removed worker is off. Its persistent sandboxes become cold. Optional body: {"reason":"..."}. The response has sandboxes_cold. Gives 409 if the worker is not down or removed. Refer to Fence lost hosts. |
POST /v1/sandboxes/{id}:migrate |
Move one sandbox to a different host. Optional body: {"node":"nod_..."} or {"node":"primary"}. |
Each node has id, kind (worker or edge), url, state (ready, suspect, down),
draining, last_seen, sandboxes (sandboxes on it that are not cold), volumes
(volumes whose home it is), version (its Spawnbox release, null before
it reports one), config_current, retirement and capacity
(free slots, free memory, reserved memory and its limit, whether memory is
short, ready templates,
warm VMs, CPU model and fingerprint). Sandboxes move only between hosts with the same
fingerprint and CPU model. retirement is null, or has id,
origin (api or autoscaler), state (draining, blocked,
ready_to_terminate or removed), migrate, reason, created_at,
ready_at, ended_at, failed_moves and waiting_for.
Each sandbox has the field node: the ID of the worker that runs it, or
null for the primary.
Usage
GET /v1/usage?from=&to=&group_by=sandboxgives one row for each tenant and each UTC hour. Withgroup_by=sandbox, it gives one row for each sandbox.- The default range is the current month. The maximum range is 93 days.
- The key must have the scope
usage:read. - Each row has these fields:
vcpu_sandmem_gib_s: the reserved size while the sandbox runs. A paused sandbox uses no vCPU or memory.disk_gib_h: the bytes that are on the disk of the host.egress_bytes: the TCP bytes sent and received.
- Limits:
- Spawnbox counts the bytes of a connection when the connection closes. Thus, an egress quota does not stop open connections.
- In open mode, Spawnbox does not count UDP and ICMP.
- Spawnbox does not measure the time when the server is stopped.
This page is the “API reference” section of README.md ↗. Found a mistake? Edit it on GitHub ↗