The Python SDK exposes stdio throughDocumentation Index
Fetch the complete documentation index at: https://docs.declaw.ai/llms.txt
Use this file to discover all available pages before exploring further.
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
| Name | Type | Default | Description |
|---|---|---|---|
cmd | str | (required) | Shell command to execute. |
envs | dict[str, str] | None | None | Environment variables merged into the process env. |
user | str | "user" | User the process runs as. |
cwd | str | None | None | Working directory. |
on_stdout | Callable[[bytes], None] | None | None | If provided, a background reader thread calls this for every stdout chunk. |
on_stderr | Callable[[bytes], None] | None | None | Same, for stderr. |
request_timeout | float | None | None | httpx timeout for the start POST only. |
Returns
AStdioProcess.
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 | None—Nonewhile 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.
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.
StdioResult
int(result) and result == 0 both work.
Threading notes
- The
on_stdout/on_stderrcallbacks run on a background daemon thread. Don’t do long blocking work inside them. send_stdin,close_stdin,killare safe to call from any thread.wait()is synchronous. For async code,AsyncSandboxprovides an equivalentstdiomodule with coroutine-based callbacks (same method names).