Skip to main content

States

Any non-terminal state can go straight to terminated. Follow a sandbox with GET /v2/ai/sandboxes/{sandbox_id}, or wait for it to end with GET …/wait.

Termination Reasons

termination_reason is always set once state is terminated. exit_code is set whenever the main process ran. A process killed by a signal reports exit_code 128 plus the signal number: 137 for SIGKILL, 143 for SIGTERM. termination_message is set in two cases only. With internal_error, it holds a short reason from Telnyx, such as the sandbox’s disk not being ready. With image_pull_failed before the sandbox ran, it holds the registry’s own message or what the image checks found (the reference, the image’s platform, ENTRYPOINT/CMD, WorkingDir, or User). It is text from your registry, shown as received with control characters removed.

Timeouts

Send "timeout": null explicitly for a sandbox with no lifetime limit. A client that drops null fields from the JSON body gets the 300 s default.
Activity for idle_timeout is an exec running, starting, or finishing, and stdin written to an exec or to the main process. Reading output, file calls, and the main process’s own work don’t count. A sandbox whose main process is a server, with nothing else going on, ends after idle_timeout. With queue_timeout: 0, a sandbox always ends queue_timeout, because resolving the image counts. The first sandbox of an account can also wait for its log bucket to be created before its queue time starts.

Stopping

POST /v2/ai/sandboxes/{sandbox_id}/terminate stops a sandbox:
  • A queued or preparing sandbox is cancelled at once.
  • A placed sandbox is stopped asynchronously. Its processes get SIGTERM, then SIGKILL if they are still running after a grace period. It reaches terminated with termination_reason: terminated_by_user and the main process’s exit_code if it ran.
  • A sandbox that already ended on its own keeps its own reason. Terminating a terminated sandbox succeeds and changes nothing.
The response returns 202 with the sandbox as it is at that moment. File calls keep working during the grace period, so results can still be fetched from a sandbox that is ending. When timeout and a terminate request overlap, the earlier one wins. A stop that comes after the main process already exited changes nothing.

Wait for a Sandbox to End

GET /v2/ai/sandboxes/{sandbox_id}/wait?timeout=10 is a long poll. It returns 200 with the sandbox as soon as it is terminated, or after at most 10 seconds. Larger timeout values are clamped to 10; 0 returns at once. Call it again until state is terminated. This waits for a long-running sandbox without holding one connection open.

Readiness

ready tells whether the sandbox can serve its purpose. Without a probe, it is true once the sandbox is running. With readiness_probe, set exactly one of:

Names and Tags

  • name (optional): 1–64 characters of A-Z, a-z, 0-9, ., _, -. It is unique among the account’s non-terminated sandboxes (409 name_conflict otherwise) and reusable once the sandbox holding it ends. Look a sandbox up with GET /v2/ai/sandboxes?name=<name>.
  • tags (optional): up to 20 key/value labels. Keys are 1–63 characters, values up to 255. Filter with GET /v2/ai/sandboxes?tag[project]=llm-ft; every given tag must match.
PATCH /v2/ai/sandboxes/{sandbox_id} with {"tags": {...}} replaces the whole tag set; {} clears it. Tags are the only thing that can change after create, and they can change on terminated sandboxes too.

Listing and Retention

GET /v2/ai/sandboxes lists sandboxes newest first. Without state, it lists only non-terminated sandboxes. Add state=terminated for finished ones, or repeat state for several. Sandboxes belong to the organization: every user in it sees and manages them. Terminated sandboxes and their execs stay readable for at least 30 days. Metrics are kept for 30 days.