strands.sandbox.stream_process
Spawn a process and stream its stdout/stderr as an async generator.
Mirrors strands-ts/src/sandbox/stream-process.ts.
The shared process-supervision engine behind the shell-based backends (Docker,
SSH): a backend builds an argv, and this spawns the process, streams its output
as :class:StreamChunk objects, and yields a final :class:ExecutionResult.
Cancellation is cooperative — cancelling the consuming task (or closing the
generator) runs the cleanup in finally, which kills the process. timeout
is wall-clock: measured from spawn and not reset by ongoing output.
stream_process
Section titled “stream_process”async def stream_process( program: str, args: list[str], *, timeout: float | None = None, enoent_message: str | None = None) -> AsyncGenerator[StreamChunk | ExecutionResult, None]Defined in: src/strands/sandbox/stream_process.py:41
Spawn a command and stream its stdout/stderr, yielding the final result.
Yields :class:StreamChunk objects as output arrives, then a single final
:class:ExecutionResult. Signal termination maps to 128 + signal (e.g.
SIGKILL -> 137). Cancelling the consuming task kills the process.
Arguments:
program- The binary to spawn (e.g."docker","ssh").args- Arguments to pass to the binary.timeout- Maximum wall-clock execution time in seconds, measured from spawn (not reset by output).Nonemeans no timeout.enoent_message- Message to surface asstderr(with exit code 127) whenprogramis not on PATH. IfNone, the underlying :class:FileNotFoundErrorpropagates instead.
Yields:
:class:StreamChunk objects for output, then a final
:class:ExecutionResult.
Raises:
TimeoutError- If execution exceedstimeoutseconds.FileNotFoundError- Ifprogramis not found andenoent_messageisNone.