Handle to a running command with streaming output and auto-reconnect.
Iterable, yielding OutputChunk objects (stdout and stderr interleaved in arrival order). Access .result after iteration to get the full ExecutionResult.
Auto-reconnect behavior:
The auto-reconnect is transparent -- the iterator reconnects and continues yielding chunks without any user intervention. If all reconnect attempts are exhausted, SandboxConnectionError is raised.
Construction modes (controlled by command_id):
command_id="", the default): the constructor
eagerly reads the server's "started" message to populate
command_id and pid before returning.command_id set): skips the started-message
read, since reconnect streams don't emit one.CommandHandle(
self,
message_stream: Iterator[dict],
control: Optional[_WSStreamControl],
sandbox: Sandbox,
*,
command_id: str = '',
stdout_offset: int = 0,
stderr_offset: int = 0
)Example:
handle = sandbox.run("make build", timeout=600, wait=False)
for chunk in handle: # auto-reconnects on transient errors print(chunk.data, end="")
result = handle.result print(f"Exit code: {result.exit_code}")
The server-assigned command ID. Available after construction.
The process ID on the sandbox. Available after construction.
The final execution result. Blocks until the command completes.
Drains the remaining stream if not already exhausted, then returns the ExecutionResult with aggregated stdout, stderr, and exit_code.
Last known stdout byte offset (for manual reconnection).
Last known stderr byte offset (for manual reconnection).
Send a kill signal to the running command (SIGKILL).
The server kills the entire process group. The stream will subsequently yield an exit message with a non-zero exit code.
Has no effect if the command has already exited or the WebSocket connection is closed.
Write data to the command's stdin.
Reconnect to this command from the last known offsets.
Returns a new handle that resumes output from where this one left off. Any output produced while disconnected is replayed from the server's ring buffer.