Skip to main content
POST /v1/agents/runtime/{runtime_id}/code/run?stream=true Runs code and delivers its output as it is produced instead of only when execution finishes. Output is streamed as Server-Sent Events. This is not a replay of buffered output at the end: the guest interpreter’s stdout and stderr are line-buffered and forwarded live through the execution plane, so a loop that prints once a second produces one event a second. Long running jobs stay observable, and an agent can act on partial output without waiting for the process to exit.

Parameters

The request body is identical to Run Code. Streaming is selected with the stream=true query parameter.

Events

Each SSE frame carries one JSON object with a type field.
Streamed code output uses the field name text, while streamed command output uses data. They are separate endpoints with separate wire contracts.
A result payload carries whichever representations the kernel produced:

Errors

When the executed code raises, an error frame is emitted before end:
The SDK surfaces this through on_error and on the returned CodeRunResponse. The CLI prints the traceback and exits non-zero.

Choosing streaming

Streaming and buffered execution return the same result shape, so switching is safe. Prefer streaming when:
  • The code runs long enough that intermediate output is useful.
  • You want to stop early based on partial output.
  • You are relaying progress to a user or to another agent.
Prefer the buffered call when you only need the final value and want one round trip.