Skip to main content
The Python SDK exposes stdio through sandbox.stdio. Use Stdio.start() to launch a process with an open stdin pipe, then send data, receive output, and close stdin or kill the process. For conceptual background see the Stdio feature overview.

sandbox.stdio.start(...)StdioProcess

Start a subprocess with an open stdin pipe. The sandbox runs the command and returns a StdioProcess handle.

Parameters

Returns

A StdioProcess.

StdioProcess

Handle for an interactive subprocess with stdin pipe. Provides bidirectional I/O: send data via send_stdin, receive output via callbacks or iteration, and manage the process lifecycle.

Properties

  • proc.cmd_id: str — server-assigned command identifier.
  • proc.exit_code: int | NoneNone while the process is running; set once the exit SSE event arrives.

Methods

proc.send_stdin(data, request_timeout=None) -> None

Send data to the process’s stdin. Accepts bytes or str; str is UTF-8 encoded.

proc.close_stdin(request_timeout=None) -> None

Close the process’s stdin pipe, sending EOF. The process sees end-of-file on its stdin.

proc.kill(request_timeout=None) -> bool

Terminate the process. Returns True if the process existed at the time of the call.

proc.wait(timeout=None) -> StdioResult

Block until the process exits. If the process was started with callbacks, this joins the background reader thread. Otherwise it drains the SSE stream inline, discarding output.

proc.stream(on_stdout=None, on_stderr=None) -> StdioResult

Block until the process exits, invoking callbacks for each output chunk. Use this when you didn’t provide callbacks at start time but want to consume output.
Raises RuntimeError if a background reader is already running (i.e. callbacks were passed to start()). Use wait() in that case.

Iterator protocol

StdioProcess is iterable when no background reader is active. Each iteration yields a (stream_type, data) tuple where stream_type is "stdout" or "stderr" and data is bytes.
Use the iterator or callbacks, not both — they consume the same stream.

StdioResult

Int-coercible — int(result) and result == 0 both work.

Threading notes

  • The on_stdout / on_stderr callbacks run on a background daemon thread. Don’t do long blocking work inside them.
  • send_stdin, close_stdin, kill are safe to call from any thread.
  • wait() is synchronous. For async code, AsyncSandbox provides an equivalent stdio module with coroutine-based callbacks (same method names).