Code execution & sandbox
When the agent runs a shell command, a Python cell, or a build, it does so inside a managed sandbox, not on the host serving the API. This page documents where that execution happens, how isolated it is, and the exact tools the agent uses, with their parameters and return shapes.
These are the agent's tools, not API endpoints
sandbox_bash, exec_command, write_stdin, edit_file, apply_patch and the repl_execute described below are tools the agent calls inside its own turn; your request cannot call them, and their parameters are not request fields. You see them only as tool events of a streaming turn. The one tool a client calls directly is repl_execute over the MCP server, with its own parameters: code, skills (skill ids whose scripts are mounted) and timeout_seconds (capped at the sandbox ceiling).
Isolation
The execution environment is chosen and operated by the platform; it is not set in the API request. You write the same tool calls either way, and isolation is an operational guarantee, not a parameter.
- Filesystem jail: file access is confined to the session workspace; path traversal outside the root is rejected before any I/O.
- Network closed by default: only a restricted set of platform hosts is reachable. Keyed third-party APIs are called through connectors, not from the sandbox.
- No connector secrets inside: connector secrets (API keys, tokens, passwords) never enter the sandbox environment: code reaches a connector through the host, which holds its credentials. os.environ carries only a connection's non-secret identifiers, the user's own variables and the variables an Environment names.
- Per-session filesystem: each session gets its own workspace. Every
sandbox_bashcall starts a fresh shell:cdand environment variables do not reach the next call, so keep intermediate state in files.
Files & persistence
| Root | Default cloud path | Purpose |
|---|---|---|
input | /tmp/input | User uploads, read-only |
work | /tmp/work | Drafts, builds, intermediate files |
output | /home/user/output | Results the agent hands to the user |
| home folder | /home/user | Default cwd; nothing saves or delivers it |
work and output survive a sandbox restart between turns. The repl_execute namespace is snapshotted and restored too; when a restore fails, the agent sees a [SYSTEM: …] note or a NameError. Files move between the cloud and the user's computer via copy_from_computer and copy_to_computer (up to 100 megabytes per file, the file is addressed by artifact_id).
On the user's computer, analyze accepts paths in the chat folder or its working directories. For a file outside those directories, copy_from_computer checks permission to import that exact file. A file can come from any local drive (D:\, C:\Work); on «Ask before changes», a file outside the home folder is copied only after you allow that path. Credential and password stores and network shares (\\server\share) are never copied; map a share to a drive letter instead. copy_to_computer writes only into the chat folder and the home folder; to write elsewhere, bind that folder to the chat. The agent passes the returned artifact_id to analyze.
Tools
A turn runs either in the cloud sandbox (sandbox_bash) or on the user's computer through the desktop app (exec_command + write_stdin). The wrong shell answers with a refusal that names the right one. edit_file edits files wherever the turn runs.
sandbox_bash: run shell / Python
One-shot, non-interactive command in the cloud sandbox. Returns captured streams plus files from output.
| Field | Type | Description |
|---|---|---|
| commandrequired | string | Shell command. Each call is a fresh shell; `grep`, `diff`, `test` legitimately exit non-zero. |
| purposerequired | string | One line for the human about what the call does. Every tool has it; required on tools that change the workspace. |
| timeout_seconds | int (1–300) | Command timeout, default 60s. The ceiling is the lesser of the sandbox limit and the turn's wait budget (300s). For long Python work, use `repl_execute`. |
| cwd | string | Absolute path or a root (`work/fetch`). Default: the home folder. Set it instead of `cd`. |
Returns:
| Field | Meaning |
|---|---|
stdout / stderr | Captured output streams. |
exit_code | Process exit code. |
command_success | false only when the command could not start (126/127) or was killed. A non-zero exit_code alone is not a failure. |
truncated | true if stdout was clipped; the full output is at the envelope's full_data_path. |
files / file_count | Files produced in the workspace by this command. |
local_paths | Map of workspace files to retrievable paths. |
repl_execute: persistent Python REPL
A Jupyter-like Python session: one process per conversation, the namespace outlives the calls, and a failed cell does not roll back what already ran. Built-in helpers (peek, grep, chunk_indices, llm_query, save_artifact, FINAL and more) help work over large data without re-loading it each step.
The call returns an execution receipt and captured output. Computed objects stay under their Python names: read_stdout(ref) reads the output, while read_first(ref) selects the receipt record. To inspect a saved object, print it in the next cell, for example print(rows). The computation does not need to run again.
A cell that outlasts the initial window keeps running while the agent's turn pauses. The runtime collects the receipt before the turn continues. The cell retains its own execution deadline. Reaching it resets the kernel. Variables from completed cells are restored from a snapshot, while name changes from the interrupted cell are lost. Writes already applied to external services remain. Reconcile their state and saved progress before retrying.
A syntax error returns its line and position for repair; by itself, it neither ends the turn nor raises the token limit. The provider response determines whether a tool call was truncated: that call is withheld from execution and retried with a larger output budget.
| Field | Type | Description |
|---|---|---|
| coderequired | string | Cell source. Split steps longer than 150 lines across cells. |
| yield_seconds | float | Initial observation window in seconds, capped by the runtime. The call returns the receipt if the cell finishes within the window. |
exec_command: live shell session
Runs a command in a shell session on the user's computer through the desktop app, in the chat's folder, using pipes. Commands that finish during the initial window return stdout and exit_code directly. A finite command that outlasts the window pauses the turn. On wake, the runtime checks the same session and reads from the saved output position. If the connection drops, the result stays unknown until a read succeeds. For servers, REPLs and watchers left running, the agent can use write_stdin with their session_id.
The agent launches Claude Code and supported ACP agents in managed mode, with a direct command, cli_agent, and task. The runtime delivers the task and handles permission requests. Standalone diagnostics such as claude auth status --text use an ordinary shell command.
| Field | Type | Description |
|---|---|---|
| commandrequired | string | Command to run in the shell session. |
| workdir | string | Folder relative to the chat's folder, or a root (`work/site`). A path outside the chat's folder is refused. |
| grace_seconds | float (0–300) | Initial observation window, default 10s. The runtime caps the window for finite commands. |
| notify_on_exit | boolean | Default `true` collects the exit result automatically. Use `false` for a server, watcher or daemon left running. |
| sandbox | "workspace" | "host" | On a Mac the shell runs under a Seatbelt profile (`workspace`, default). `host` lifts it for one call and shows the person a consent card. |
| justification | string (≤300) | Required with `sandbox="host"` and only with it: one sentence for the consent card. |
Returns session_id, pid, stdout, status (running / exited / killed), exit_code, alive and next_since: pass it as since to write_stdin to continue reading from the same spot. dropped_bytes > 0 means the start of the output was evicted from the buffer and is lost.
write_stdin: drive a live session
Reads the output and status of an exec_command session, including a retained result after exit. A running session also accepts input. Append \n to submit a line.
| Field | Type | Description |
|---|---|---|
| session_idrequired | string | Session id returned by exec_command. |
| input | string | Characters to write to stdin. Append \n to submit a line. An empty string (default) only reads output; a lone \u0003 is Ctrl-C. |
| since | int | `next_since` from the previous response; returns only output after it. Omitted, it reads output produced after this write. |
| wait_seconds | float (0–300) | Output window for interactive sessions. Use 0 with empty input for an immediate snapshot. A positive wait with empty input on a live finite command pauses the turn until its result is ready. |
edit_file and apply_patch: surgical file edits
edit_file creates, overwrites, edits, deletes and renames one file wherever the turn runs (the cloud or the user's computer); op selects the operation. apply_patch takes a V4A patch across several files and edits: the patch headers name the files, and it lands whole or not at all. Whole-line matching tolerates edge whitespace and typographic punctuation; missing or ambiguous text returns diagnostics so the agent can revise the edit.
What you see through the API
Tool calls arrive on the OpenAI-compatible endpoint as named samreshuuu.tool events (tool_started / tool_completed) when a streaming request sets tool_events: true (Streaming). repl_execute is also exposed to external clients through the MCP server.
Full tool list
This page covers the code-execution tools. For the complete catalog across all categories (web, memory, connectors, media, …) see Agents → Available tools.