Skip to main content
A sandbox is ephemeral; an agent’s work often is not. An agent session is a durable wrapper around a series of executions: it carries a budget, keeps context across sandbox rotations, and can be reattached to after a client disconnects. Use a plain sandbox when the work is one command. Use a session when an agent will run many commands over a long enough period that the sandbox underneath it may be replaced.
Sessions are served from the sandbox controller at https://api.sandbox.stateset.com/api/v1, and authenticate with the sandbox scheme β€” Authorization: ApiKey <key>, not Bearer. The key needs sandbox:write for anything that mutates a session, and sandbox:read to inspect one.

Create a session

The budget is the point. All three limits are optional, and a session with none of them set has nothing stopping it.
costCapCents is a cap on the session, not a per-execution limit, and it is accounted after each execution rather than predicted before one. A single expensive command can cross the cap; the session stops afterwards. Size the cap for what you can afford to overshoot by one execution.

Run work in it

timeoutMs is bounded to 1s–10min. Each execution is charged against the budget, and the response carries what remains.

Rotation, and what survives it

A session outlives the sandbox it started on. When the underlying sandbox reaches its timeout, the session enters rotating, provisions a fresh one, and carries context across:
  • the working directory
  • environment variables
  • any custom state you have written to the session context
Files written outside the working directory do not survive a rotation, and neither do running processes unless rotation.includeProcessState is set. Anything the next sandbox needs belongs in the session context or in artifact storage β€” not in /tmp.

Surviving a disconnect

A session is addressable after your client dies. Reattach with the clientId you supplied at creation:
Send POST .../heartbeat while you hold a session so the controller can tell a live client from an abandoned one.

Lifecycle

Next steps

Active-horizon agents

The durable supervisor that drives sessions like these across hours.

Sandbox API flow

The one-shot path, for work that fits in a single sandbox.

Runtime selection

Container, gVisor or MicroVM for the isolation field above.

Security guide

What a session can reach, and how to narrow it.