sandbox.Provider from pkg/agents/sandbox. The provider creates and reconnects execution environments; tools run commands and access files. Docker and Kubernetes use the HasteKit sandbox daemon, while E2B and Daytona use their service protocols.
Configure a provider
Importpkg/agents/sandbox/providers/docker, pkg/agents/tools, and github.com/moby/moby/api/types/container:
sandboxTools to AgentConfig.Tools. The second argument is a configured profile name. Supply an image with the sandbox daemon and Bash; the provider does not build it. Keep the provider open until all runs finish.
Choose a backend
hastekitgateway.Config.NewSandboxClient() is a gateway-specific HTTP client implementing the same provider contract. Applications can also implement sandbox.Provider directly.
State and commands
sandbox.Acquire reconnects using the reference saved under sandbox.StateKey in run state, or creates a resource when no reference exists. Tools return state updates that later calls and persisted turns reuse. Approval and middleware run before provisioning.
The bash tool executes bash -c with the supplied code. Use its workdir argument for a working directory; cd affects only that invocation. Nonzero exit codes are command results, not transport errors.
Separate threads do not automatically share compute, even when they share a session. Concurrent runs of the same session are unsupported. A corrupt reference, scope mismatch, or missing saved resource fails rather than silently provisioning a replacement. Changing creation settings does not reconfigure an existing environment.
Lifecycle
Configure mounts, resource limits, networking, credentials, and cleanup in the provider. A crash before the resource reference is persisted can orphan compute. Command cancellation stops waiting; remote process termination depends on the provider. Do not retry external commands blindly. The SDK repository contains daemon image instructions indeployments/sandbox and backend configuration guides beside each provider. Use approval or middleware for sensitive operations.