strands.sandbox.docker
Docker sandbox — executes commands in a Docker container via docker exec.
Mirrors strands-ts/src/sandbox/docker.ts.
DockerSandbox
Section titled “DockerSandbox”class DockerSandbox(PosixShellSandbox)Defined in: src/strands/sandbox/docker.py:14
Execute commands in a Docker container via docker exec.
A thin :class:PosixShellSandbox backend: file and code operations are
inherited (run as shell commands), and only :meth:execute_streaming is
implemented, building the docker exec argv.
__init__
Section titled “__init__”def __init__(container: str, *, working_dir: str | None = None, user: str | None = None) -> NoneDefined in: src/strands/sandbox/docker.py:22
Initialize the Docker sandbox.
Arguments:
container- ID or name of a running Docker container.working_dir- Working directory for executed commands. IfNone, no-wflag is set and commands run in the container’s configured working directory. The path must exist and be writable by the effectiveuser.user- User to run commands as, in"uid","uid:gid", or"name"form. IfNone, no--userflag is set and commands run as the container’s configured user.
execute_streaming
Section titled “execute_streaming”async def execute_streaming( command: str, *, timeout: float | None = None, cwd: str | None = None, env: dict[str, str] | None = None, **kwargs: Any) -> AsyncGenerator[StreamChunk | ExecutionResult, None]Defined in: src/strands/sandbox/docker.py:39
Execute a command in the container, streaming output.
Arguments:
command- The shell command to execute.timeout- Maximum execution time in seconds.Nonemeans no timeout.cwd- Working directory for this command, overridingworking_dir.env- Environment variables to set, passed asdocker exec -eflags.**kwargs- Additional keyword arguments for forward compatibility.
Yields:
:class:StreamChunk objects for output, then a final
:class:ExecutionResult.
Raises:
ValueError- If an environment variable name is invalid.TimeoutError- If execution exceedstimeoutseconds.