AsyncCommandHandle(
self,
message_stream: AsyncIterator[dict],
control: Optional[_AsyncWSStreamControl],
sandbox| Name | Type |
|---|---|
| message_stream | AsyncIterator[dict] |
| control | Optional[_AsyncWSStreamControl] |
| sandbox | AsyncSandbox |
| command_id | str |
| stdout_offset | int |
| stderr_offset | int |
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.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}")