/blog/agent-sandboxes
Agent Sandboxes
Now that LLMs are actually good, it's time for me to start offloading some work to them. However, with stories of coding agents deleting important data, I decided to only allow them to run in sandboxed environments.
There are quite a number of sandboxing solutions but only 2 of them really fit (my) bill. Preferably, they must run the agents locally in a separate VM, can access only the minimal amount of host files and let the user modify network permissions. Based on my research, only docker-sbx and microsandbox really meet my criteria, albeit not perfectly.
You can check out my setup for coding agents on GitHub. So far, I only have set ups for OpenCode on docker-sbx and microsandbox, since these are the 2 most comprehensive sandboxing solutions.
Feature Matrix
| Feature | docker-sbx | microsandbox | smolvm |
|---|---|---|---|
| License | Proprietary1 | Apache-2.02 | Apache-2.03 |
| Bind mounts | ⚠️ Can only set the source directory path. Path to mounted directory inside the microvm is the same as that in the host. Example: sbx create opencode $HOME/project but no sbx create opencode $HOME/project:/home/agent/project 4 | ✅6 | ✅7 |
| Modifying bind mounts | ❌ | ❌8 | ❌ |
| Port publishing | ✅ sbx ports --publish [[HOST_IP:]HOST_PORT:]SANDBOX_PORT[/PROTOCOL] 9,10 | ✅ -p 8080:80[/udp] (loopback) or -p 0.0.0.0:8000:80[/udp] (all interfaces) 11 | ✅ -p HOST:GUEST[/udp]. Ports can be a range 13 |
| Modifying ports | ✅ sbx ports --unpublish 9 | ⚠️ Changes only take effect after restart: msb modify -p 8080:3000 --next-start/--restart / --port-rm 8,11 | ✅ machine update -p add / --remove-port 7 |
| Socket publishing | ❌ | ✅ --vsock HOST_PATH:PORT[/stream|/dgram] 11 | ✅ --expose-socket GUEST[:HOST] / --mount-socket HOST:GUEST 7 |
| Modifying sockets | ❌ | ❌ | ❌ |
| Access to host | ✅ host.docker.internal/gateway.docker.internal | ✅ host.microsandbox.internal. Requires --net host12 | ✅ --allow-host-loopback. Inside the guest, connect to http://localhost:11434 to access self-hosted Ollama in the host.7 |
| Images/templates | ✅ sbx templates. Build using Dockerfiles13 | ✅ Any OCI Image/root filesystem from host/.qcow2 file.5 | ✅ Any OCI Image. Pack any small machines into a .smolmachine file.5,14 |
| Egress policy | ✅ deny-by-default; sbx policy allow/deny network <domain> 15,16 | ✅ --net-rule <action>[:<direction>]@<target>[:<proto>[:<ports>]] / --no-net airgap / --net-default deny 12 | ✅ --net + --allow-host[-pattern]/--allow-cidr/--outbound-localhost-only7 |
| Modifying egress | ✅ sbx policy allow/deny/rm network 15,16 | ❌8 | ✅ use machine update. Add allow rules or remove them: --remove-allow-host/--remove-allow-cidr/--remove-allow-udp. Can also turn on/off networking in general --net/--no-net 7 |
References
- Docker Sandboxes GitHub Repo: https://github.com/docker/sbx-releases
- Microsandbox GitHub Repo: https://github.com/superradcompany/microsandbox
- Smol Machines GitHub Repo: https://github.com/smol-machines/smolvm
sbx createReference: https://docs.docker.com/reference/cli/sbx/create- Microsandbox Overview: https://docs.microsandbox.dev/sandboxes/overview
- Microsandbox Volumes: https://docs.microsandbox.dev/sandboxes/volumes
- Smol Machines Lifecycle and CLI Reference: https://smolmachines.com/docs/local/machine-lifecycle-cli-reference
- Microsandbox Live Modify: https://docs.microsandbox.dev/sandboxes/tuning
sbx portsReference: https://docs.docker.com/reference/cli/sbx/ports- Docker Sandboxes Usage: https://docs.docker.com/ai/sandboxes/usage
- Microsandbox Sandbox Commands: https://docs.microsandbox.dev/cli/sandbox-commands
- Microsandbox Networking Overview: https://docs.microsandbox.dev/networking/overview
- Docker Sandboxes Base Images: https://docs.docker.com/ai/sandboxes/customize/author/base-images
- Smol Machines Pack and .smolmachine CLI: https://smolmachines.com/docs/local/pack-and-smolmachine-cli
- Docker Sandboxes Network Access Policy: https://docs.docker.com/ai/sandboxes/governance/access-controls/network
sbx policyReference: https://docs.docker.com/reference/cli/sbx/policy