Skip to main content
Live. This area is documented as current, user-reliable behavior.

Goal

Run a command, a script or a few files in a clean, isolated machine and get the result back without managing a sandbox yourself.

Prerequisites

  • A StackShift API key, a signed-in CLI, or a connected agent allowed to run code in short-lived sandboxes.
  • A sandbox template reference with its digest, such as TEMPLATE@sha256:DIGEST. Copy it from Sandbox templates in the dashboard.

Workflow

1
Pick the template that has the language and tools your code needs.
2
Give exactly one of command (a shell line), argv (a program and its arguments, no shell) or script (text to pipe into interpreter).
3
Add any files the code needs. They are written into /workspace before the command starts.
4
Send POST /api/v1/sandboxes/run, or use stackshift sandbox run, an SDK or the sandbox_run tool.
5
Read exit_code, stdout and stderr from the answer. The sandbox is already gone.

Run or keep

A one-shot run is the quickest way to run code: there is nothing to create first and nothing to clean up after. Use it for tests, scripts, code an agent wrote, and checks in a pipeline. Keep a sandbox when you need files or processes to carry over between calls, and use a Computer when you want a whole machine that stays, pauses and comes back where it was.

The sandbox is always deleted

Every run creates a new sandbox and deletes it before the answer comes back, whatever happened: the code succeeded, exited with an error, ran out of time, a file could not be written, or the sandbox never became ready. It is also deleted if your connection drops while the run is in progress. Nothing from one run is visible to the next. Each run starts from the clean template.

Request

  • template (required): the template reference with its digest.
  • profile: the size of the sandbox, such as ci, customer_code or plugin. Defaults to ci.
  • command: a shell line, such as npm test && npm run lint.
  • argv: a program and its arguments, run without a shell, such as ["python3", "main.py"].
  • script and interpreter: script text passed on standard input to the interpreter, such as python3 or node. The interpreter defaults to sh and is only accepted with script.
  • files: up to 100 files with path and text content, 8 MB in total. Paths are inside /workspace.
  • environment: variables for the command, as an object of names and values.
  • cwd: the working directory. Defaults to /workspace.
  • timeout_seconds: how long the command may run, from 1 to 600. Defaults to 60.
Run a Python file

Answer

  • state: succeeded, failed, timed_out, oom_killed or cancelled.
  • exit_code: the command’s exit code. It is left out when the command was stopped before it could exit, for example when it ran out of time.
  • stdout and stderr: the first 64 KB of each stream. stdout_truncated and stderr_truncated say whether more was cut off.
  • start_ms: milliseconds until the sandbox was ready to run code. duration_ms: milliseconds for the whole run, including writing files.
  • sandbox_id and execution_id: identifiers for support and your own logs. The sandbox no longer exists.

From the SDKs

The Go, TypeScript and Python sandbox SDKs all have a run call that sends the same request and waits for the answer. The Go and Python clients wait up to five minutes longer than your timeout, so a long run is not cut off by the client; the TypeScript client waits until the answer arrives.

From the CLI

stackshift sandbox run copies local files in, prints the command’s output to your terminal and exits with the command’s exit code. See the CLI reference for every flag.

From a connected agent

Agents connected over MCP use the sandbox_run tool. It takes the same fields as the request above and runs at once, without asking you first, so it needs its own permission: tick “Run code in a short-lived sandbox” when you connect the agent or under Change access. Without that permission the tool answers insufficient_scope for sandbox.run, and the agent can ask you to add it.

Start times

The Sandboxes and Computers pages show how long machines take to be ready, split into warm starts, which use a machine we already prepared, and cold starts, which boot a new one. Each shows the typical time and the time 95 out of 100 starts finish within. GET /api/v1/sandboxes/start-stats returns the same numbers. Each item has class (sandbox or computer), start (warm or cold), nodes, samples, p50_ms, p95_ms and max_ms.

What you pay for

A run is billed like any sandbox of its profile, for the seconds it exists, from start until it is deleted. There is no charge after the answer comes back.

Expected result

One answer with the exit code, up to 64 KB of standard output and 64 KB of standard error, how long the sandbox took to be ready and how long the whole run took.

Common failures

  • 400 invalid_request with “give exactly one of command, argv or script”. Send only one of the three.
  • 400 invalid_request with “timeout_seconds must be between 1 and 600”. Ask for 600 seconds or less, or use a sandbox you keep for longer work.
  • 400 invalid_request with “files exceed 100 files or 8388608 bytes”. Send fewer or smaller files, or download larger inputs from inside the command.
  • 400 invalid_request with “unknown sandbox profile”. Use a profile from GET /api/v1/sandboxes/catalog, such as ci.
  • 502 run_failed with “the sandbox did not start”. Nothing ran and the sandbox was deleted. Try again; if it keeps failing, check the template on the Sandbox templates page.
  • stdout_truncated or stderr_truncated is true. Only the first 64 KB of that stream came back. Write large output to a file and print a summary instead.

Computers: a cloud computer for any agent

A Computer is a full Linux machine, with or without a desktop, that an agent or a person can create, drive, pause, fork and delete from anywhere.

Computers CLI reference

Every stackshift computers command: open a shell, create, list, run commands, move files, publish ports, fork, pause, snapshot and manage keys.

stackshift sandbox run

Run a command or script in a fresh sandbox, print its output and delete the sandbox, in one command.

Connection access and approvals

Understand selected resources, permitted actions, owner decisions and revocation.