Install the extension
From the agent folder:0.4.2 requires Harnest >=1.0.0,<2 and docker>=7.1,<8. The host must provide a reachable Docker daemon.
Declare a Docker sandbox
Createsandbox/python.py. The exported variable must match the filename:
sandbox/python.py
"python" to each consuming agent’s sandboxes=[...] grant. Call it from an authored tool through context.sandboxes["python"]. Exactly one of image or docker_path is required; prefer an immutable image digest in deployments.
Sandbox configuration
options carries supported ADK parsing and retry options, while metadata is attached to the portable sandbox declaration. Construction validates immutable configuration without contacting Docker; the first execution starts provider resources lazily.
Add service containers
Attach bounded services when the primary Python container needs another process:sandbox/worker.py
network_policy denies external egress. Use docker.network(internal=False) only with SandboxNetworkPolicy.unrestricted(). That choice gives every topology container the same unrestricted egress authority.
Services start in declaration order. A declared readiness command becomes a bounded Docker health check, and submitted Python does not run until every service is healthy. Each service has its own SandboxBudget. Cleanup removes the primary container, service containers in reverse order, and then the owned network. If cleanup cannot be confirmed, the topology remains poisoned and replacement is blocked until cleanup succeeds.
Choose a reuse scope
Retained scopes reuse the container and its
/tmp scratch files while that identity remains cached, but not live processes or durable storage. Every successful call stops remaining processes. max_scopes defaults to 8 and evicts the least recently used retained container before admitting another identity.
Set network authority
The extension supportsSandboxNetworkPolicy.none() and SandboxNetworkPolicy.unrestricted(block_private_networks=False). No-network mode is the default. Exact host or port allowlists, and unrestricted networking with private-network blocking, fail closed because this provider does not yet enforce those controls at Docker’s network boundary.
Network policy is provider-enforced authority. Validating a URL in an Agent Tool does not replace it. Use another sandbox provider when a workload requires exact destination enforcement.
Understand deadlines and cleanup
The all-in deadline covers queue admission, image and container startup, and execution. SDK transport timeouts for image preparation and container creation are constrained by the remaining deadline; a host watchdog and control checks bound execution. Output is bounded while streaming; timeout, cancellation, overflow, and failed startup poison the container instead of returning it to a reuse pool. Cleanup receives a separate bounded five-second window. The provider retains ownership and blocks replacement when termination is uncertain. Startup errors identify the failed phase without exposing raw SDK details. Managed containers carrydev.harnest.* labels for operator inventory.
Docker startup, network, service, execution, and cleanup operations emit correlated logs and traces through Harnest observability. Every signal carries harnest.extension.name=docker. Topology IDs and service names make owned resources traceable without recording image references, commands, environment values, user/session identities, readiness output, or raw Docker errors.
Security boundary
Docker daemon access is highly privileged. Protect its socket or remote API, restrict who can configure this extension, and use trusted digest-pinned images. Containers run as a non-root user with a read-only root filesystem, dropped capabilities,no-new-privileges, bounded /tmp, and no host mounts. Docker still shares the host kernel; choose a stronger provider for higher-risk isolation.
The extension does not transfer input or output files. Use stdout or a provider with an explicit file contract. See Sandboxing for agent grants, authored-tool usage, custom providers, and failure handling.
Public API and limits
A topology supports up to eight services. Each service allows 16 aliases, 32 declared ports, 64 environment entries, and 64 command arguments; bounded authored string values may use up to 8 KiB. Readiness permits 1 to 100 attempts with finite timing values. Service names and aliases must be unique portable lowercase DNS labels. These checks run before the Docker SDK receives configuration.