Blog 1 — Docker Sandboxes Series
Docker Sandboxes from Zero — Why They Exist, Setup, First Sandbox & Basic Isolation
What We Are Building
By the end of this blog you will understand why AI coding agents are risky on a normal laptop, install the sbx CLI, launch your first isolated sandbox, see the isolation boundary with your own eyes, and clean everything up properly.
No paid AI subscription is required. We use the shell agent.
Why This Matters
AI coding agents are useful because they act on their own. They install packages, edit files, run tests, build Docker images, and sometimes run commands you would never type yourself.
If you run them directly on your machine they can:
- Change or delete files outside the project
- Install system packages that break your setup
- Talk to your host Docker daemon
- Reach any network destination
- Accidentally expose credentials already present in your environment
Normal containers share the host kernel. Mounting the Docker socket gives the agent the same power as you. Full virtual machines are heavy and slow to start.
Docker Sandboxes solve this by giving each agent its own lightweight microVM.
Before vs After — The Core Problem
Explanation of the diagram
Left side shows the dangerous default: the agent runs with the same power as you on the host.
Right side shows the sandbox approach: the agent is locked inside a microVM. Only the project folder is shared. Everything else stays isolated.
What You Should Know Before Starting
- Comfortable with a terminal
- Free Docker account
- Supported platform:
- macOS
- Windows 11 with Windows Hypervisor Platform enabled
- Ubuntu 24.04+ with KVM working
Docker Desktop is not required. (No blocker for corporates...)
Environment Setup
Install the sbx CLI
macOS
brew trust docker/tap
brew install docker/tap/sbx
Ubuntu / Linux
curl -fsSL https://get.docker.com | sudo REPO_ONLY=1 sh
sudo apt-get install docker-sbx
sudo usermod -aG kvm $USER
newgrp kvm
Windows
winget install -h Docker.sbx
Verify:
sbx version
Sign in
sbx login
Step 1 — Create a Simple Project
mkdir -p ~/sandbox-lab
cd ~/sandbox-lab
echo "hello from the host" > note.txt
Step 2 — Launch the First Sandbox
sbx run --name first-sandbox shell
On the first run choose the Balanced network preset (recommended).
You are now inside a Bash shell that lives inside the microVM.
Step 3 — Look Around Inside the Sandbox
pwd
ls -la
cat note.txt
whoami
docker version
Open a second terminal on the host:
sbx ls
High-level Sandbox Architecture (what you just created)
Explanation of the diagram
You talk to the sbx CLI. The CLI starts a microVM. Inside that microVM the agent, its Docker daemon and its filesystem live. The only connection back to the host is the workspace folder you chose.
Step 4 — Prove the Isolation
Inside the sandbox:
echo "written from inside the sandbox" >> note.txt
echo "created inside sandbox" > from-sandbox.txt
docker pull alpine:latest
docker images
On the host:
cat ~/sandbox-lab/note.txt
ls ~/sandbox-lab
docker images | grep alpine || echo "alpine image is NOT on the host"
Note: Ideally you should see message alpine image is NOT on the host as output but as I'm using postgres alpine image for another application it showed up but you can observe this alpine images is not what we pulled in the sandbox.
Isolation Boundary Diagram
Explanation of the diagram
Files in the project folder move both ways (live mount).
The sandbox Docker daemon has no path to the host Docker daemon. Images and containers stay inside the microVM.
What Just Happened Internally
The microVM has its own kernel. The agent has full power inside the microVM (including sudo). Network traffic goes through a host-side proxy that enforces the policy you chose. Credentials (when we use them later) are injected by the proxy and never stored inside the VM.
Let’s Break It (Gently)
Inside the sandbox try:
curl -I https://koti.dev
If it is blocked under Balanced policy, that is expected.
On the host allow it:
sbx policy allow network koti.dev
Retry. It should now work.
Production Thinking
In real work I always:
- Start with Balanced or stricter
- Give every sandbox a clear name
- Prefer
--clonefor experimental or untrusted agent work - Treat
sbx rmas the normal way to finish a session
Security Considerations
- The agent is powerful inside the sandbox. Do not treat it like a normal restricted container.
- The workspace is read-write by default.
- Never put long-lived secrets as normal environment variables inside the sandbox (we cover the proper way in the next blog).
Common Mistakes
- Forgetting the
kvmgroup on Linux → sandbox will not start - Skipping
sbx login - Expecting host Docker to see images built inside the sandbox
- Leaving many sandboxes running → disk fills up
Troubleshooting
| Problem | Quick check | Fix |
|---|---|---|
sbx not found |
Installation | Re-run install steps |
| KVM error on Linux | `lsmod \ | grep kvm` |
| Sandbox stuck | sbx ls |
sbx stop then sbx rm
|
| Need clean state | — |
sbx reset (destructive) |
Also useful:
sbx diagnose
Cleanup
sbx stop first-sandbox
sbx rm first-sandbox
sbx ls
Your ~/sandbox-lab folder remains. Only the microVM is gone.
What We Learned
- AI agents need strong isolation. MicroVMs give that isolation without the weight of full VMs.
- The
sbxCLI is the current free way to use Docker Sandboxes. - Workspace is shared; almost everything else stays inside the sandbox.
- You can now install, launch, inspect and cleanly remove a sandbox.
What’s Next?
In Blog 2 we take full control of the environment: how files persist, the difference between direct mount and clone mode, network policies in depth, and the safe way to inject secrets so the agent never sees the real values.
References
- https://docs.docker.com/ai/sandboxes/ — official overview
- https://docs.docker.com/ai/sandboxes/get-started/ — installation and first run
- https://docs.docker.com/ai/sandboxes/architecture/ — microVM and isolation details
- https://docs.docker.com/reference/cli/sbx/ — command reference
All commands and behaviour verified against current official documentation (August 2026).














Top comments (0)