Sessions are one of three ways to run commands in a sandbox. For a synchronous, buffered command or an unnamed interactive TTY, see Exec.
Identity
A session is scoped to asandbox_id and keyed by session_name, which must match ^[a-z][a-z0-9-]{0,31}$ — lowercase, starting with a letter, up to 32 characters. There’s no separate session ID; the name is the identifier within its sandbox.
Creating a session
session_create tool covers this.
The request body extends the common command shape (cmd, env, path) with session-specific fields:
string
required
Session name. Must match
^[a-z][a-z0-9-]{0,31}$.string[]
required
Argv to run. At least one element.
object
Environment variables to set.
string
Working directory.
integer
Terminal width, 1–512.
integer
Terminal height, 1–512.
boolean
default:"false"
Whether to replace an existing session of the same name.
201 with { "session": { ...SessionInfo } }.
Name collisions
Session state
EachSessionInfo reports:
string
required
The session name.
string[]
required
The argv the session was started with.
string
required
The session’s working directory.
string
required
One of
UNSPECIFIED, STARTING, IDLE, ATTACHED, EXITED, KILLED, FAILED.boolean
required
Whether a client is currently attached.
integer
required
Start time.
integer
required
Last observed activity.
integer
End time, once the session has reached a terminal state.
object
{ exit_code, signaled, signal }, present once the session has exited.EXITED, KILLED, and FAILED are the terminal states referenced above under name collisions; STARTING, IDLE, and ATTACHED are all live.
Sessions and suspension
A session’s process never blocks idle suspend by itself. Only an attached client does, for as long as it stays connected — a quiet, detached session lets the sandbox warm-suspend on its normal idle schedule, and survives the resume with its process and replay buffer intact, the same session rather than a new one. Output the session keeps producing while detached still counts as activity and defers idle suspend on its own. Attaching to a session on a suspended sandbox wakes it, the same way exec traffic does — see Sandboxes for the resume path.Listing sessions
session_list tool covers this.
Returns SessionListResponse:
SessionInfo[]
required
All sessions tracked for the sandbox.
boolean
required
Whether the sandbox was suspended when this list was produced.
Listing sessions never wakes a suspended sandbox. If the sandbox is suspended, the response answers from a snapshot of session state taken at suspend time, and
sandbox_suspended is true — it does not resume the sandbox to get a live answer. To act on the sessions themselves, resume the sandbox first (see Sandboxes).Attaching to a session
AttachStartRequest), and admission work. Multiple clients can attach to the same session.
session_attach MCP tool: an agent can start and stop background work via session_create/session_kill but can’t stream its live output.
Killing a session
session_kill tool covers this, with signal and grace_ms fields matching the REST body.
Request body (SessionKillRequest, optional):
string
default:"TERM"
One of
TERM, KILL, INT, HUP.integer
default:"5000"
Milliseconds to wait after the signal before the session is considered killed, 0–60000.
200 with { "session": { ...SessionInfo } } reflecting the signal having been delivered.