Async handle to a running command with streaming output and auto-reconnect.
Async iterable, yielding OutputChunk objects (stdout and stderr interleaved in arrival order). Access .result after iteration to get the full ExecutionResult.
Auto-reconnect behavior:
Construction modes (controlled by command_id):
command_id="", the default): call
await handle._ensure_started() after construction to read the
server's "started" message and populate command_id / pid.command_id set): skips the started-message
read, since reconnect streams don't emit one.AsyncCommandHandle(
self,
message_stream: AsyncIterator[dict],
control: Optional[_AsyncWSStreamControl],
sandbox: AsyncSandbox,
*,
command_id: str = '',
stdout_offset: int = 0,
stderr_offset: int = 0
)Example:
handle = await sandbox.run("make build", timeout=600, wait=False)
async for chunk in handle: # auto-reconnects on transient errors print(chunk.data, end="")
result = await handle.result print(f"Exit code: {result.exit_code}")
| Name | Type |
|---|---|
| message_stream | AsyncIterator[dict] |
| control | Optional[_AsyncWSStreamControl] |
| sandbox | AsyncSandbox |
| command_id | str |
| stdout_offset | int |
| stderr_offset | int |
The server-assigned command ID. Available after _ensure_started.
The process ID on the sandbox. Available after _ensure_started.
The final execution result. Awaitable.
Last known stdout byte offset (for manual reconnection).
Last known stderr byte offset (for manual reconnection).