Runs
A run is one execution of an agent or task. Use runs for direct messages, follow-ups, and real-time output.
Create a run
Streaming (default and recommended)
Use the context manager so the stream closes cleanly even if you exit early:
See Streaming & Events for event types, text-only streaming, and reconnection. Or pass stream=False and poll:
teammate_idis the wire name for the agent id: JSON request and response bodies keep it. The SDK acceptsagent_id(canonical) andteammate_idalike.
Run options
All run options
Replies inherit task_setup_tools and feedback unless overridden.
Follow up on a run
A follow-up continues the same run: it re-opens the run, keeps the prior context, and does not consume a new run-count slot (it reuses the original run id and only burns tokens).
runs.reply() inherits the run's settings: permission mode keeps applying, and AskUserQuestion stays enabled on runs created with human_in_the_loop: true. Pass human_in_the_loop: false on the reply to pin non-interactive behavior.
Structured output
Pass a JSON Schema as output_schema and the run returns typed data on output_data, so you can act on fields instead of parsing prose.
Schema rules and gotchas
- The schema root must be
"type": "object", sooutput_datais always an object. - Inline your definitions.
$refand$defsare rejected. Pydantic'smodel_json_schema()and zod both emit$defsfor nested models, so flatten before sending. output_datacan benullon a completed run. A run cut short by truncation, a pause, or a spend limit still completes, with its textoutputintact but no structured result. Always null-check.- The schema sticks to the run: replies, resumes, and retries stay structured without re-sending it.
run.completedwebhooks carryoutput_datatoo.
Run outcome
GET /runs/{id}/outcome returns the condensed result of a run in one call (the agent's closing message, the structured result, and what the run cost) instead of the full transcript.
Outcome fields
run.status values: running, paused, awaiting_approval (waiting for user input or approval), completed, failed, cancelled, closed, archived.
Execution environment
Every run executes in an isolated cloud sandbox: a fresh, per-account Linux environment where the agent's tools (bash, file edits, computer use) run, away from your data and ours. A run streams a sandbox-connecting event while the environment is readied. The first run of a session boots the sandbox (a few to tens of seconds); later runs in the same session reuse the warm one. A busy account can briefly hit SANDBOX_CONCURRENCY_LIMIT (HTTP 429) when too many sandboxes are live at once; retry with backoff. No provisioning or configuration needed.
Run files
Attach input files with files= on runs.create (see Files). Runs can also generate files; list and download them after execution:
Next: Agents · Tasks · Streaming & Events · Webhook Events
