Dev.to Security 🔐 Cybersecurity 👁 0 📖 11 min read

Give Your Coding Agent sudo, Not Your Laptop: Docker Sandboxes in Practice

The local steps ran on Mac with sbx 0.54.1; the GitHub secret and cloud parts come from Docker's docs. If you use Claude Code or Codex every day, you know how this goes. At first you approve every command. By the twenti

Give Your Coding Agent sudo, Not Your Laptop: Docker Sandboxes in Practice

The local steps ran on Mac with sbx 0.54.1; the GitHub secret and cloud parts come from Docker's docs.

If you use Claude Code or Codex every day, you know how this goes. At first you approve every command. By the twentieth npm install you're tired of clicking yes, so you let the agent run on its own.

From that point on, the agent is working on your laptop, in your shell, with your files and your credentials, and nobody is watching each step. Usually nothing goes wrong. But "usually" isn't a security model.

Docker Sandboxes are Docker's answer to this. In this post I'll cover what they are, how to set one up, and what they don't protect you from.

Why a normal container isn't enough

Most of us would reach for a container first. Put the agent in a container and call it done.

The problem is that agents usually need Docker too, to build an image or start a test database. The quick fix is to mount /var/run/docker.sock into the container. With a typical rootful Docker daemon on Linux, that gives the agent enough control to start a privileged container and mount the host filesystem. Docker's own docs say only trusted users should control the daemon (Docker daemon attack surface). Once the socket is mounted, the container is still there, but it isn't protecting much.

A container does not make the code inside it trustworthy. An agent decides for itself what to install and run, and it can be tricked by what it reads. Docker said as much when it relaunched its brand on 19 November 2026: "Containers isolate workloads. But agents aren't workloads. Agents are actors." (Docker). That's a marketing line, but the point behind it is right.

What a Docker Sandbox is

A Docker Sandbox is a small virtual machine (a microVM) where an agent can work across multiple sessions. You manage it with a CLI called sbx. Each sandbox has its own Linux kernel, so the agent is separated from your machine by a hypervisor, not just by Linux namespaces. Docker built its own VMM for this. It uses the native hypervisor on each platform: Hypervisor.framework on macOS, Windows Hypervisor Platform on Windows and KVM on Linux (architecture post).

Inside the VM, the agent gets its own Docker Engine. It can run docker build, docker run and docker compose without touching your host daemon. The isolation docs put it plainly: "The agent has no path to your host Docker daemon."

For local sandboxes, network access follows a deny-by-default policy. Outbound TCP only reaches destinations a rule allows, UDP is off, ICMP is blocked, and DNS goes through a resolver that applies the same rules (default security posture).

Proxy-managed credentials stay outside the local VM. When you store an API key or token with sbx secret, a proxy on your host adds it to matching outgoing requests. The agent sees a placeholder, not the real value. This doesn't protect secrets you leave in project files, or credentials an agent saves inside the VM (credential docs).

Docker Sandbox architecture: the agent runs in a microVM with its own kernel and Docker Engine; a host-side proxy enforces network policy and injects credentials

Inside the VM the agent has a lot of freedom. It runs as a non-root user with sudo, it can install packages with apt, pip or npm, and it can run containers. That's on purpose. Docker relies on the VM boundary rather than restricting the agent's privileges inside it.

The trade-offs are a slower first run, while the agent image is pulled, and one more environment to manage. For code you trust, regular containers are still fine.

Setting one up

You don't need Docker Desktop for this. sbx is a standalone CLI. Local sandboxes need macOS 14 or later on Apple silicon, Windows 11 with Windows Hypervisor Platform turned on, or Ubuntu 24.04 or later with KVM (install docs).

You'll need a Docker account to sign in. Install the CLI, then log in:

# macOS
brew trust docker/tap
brew install docker/tap/sbx

# Windows
winget install -h Docker.sbx

# then, on any platform
sbx login

If you skip sbx login, the first sbx create or sbx run starts the sign-in for you.

On Ubuntu, sbx comes from Docker's apt repository as the docker-sbx package. Follow the install docs for that.

Then go to your project and start an agent (get started guide):

cd ~/my-project
sbx policy init balanced
sbx run --name my-sandbox claude

sbx policy init balanced sets your network rules up front. The Balanced preset allows common development services and blocks everything else until you approve it. If you skip this step, sbx asks you to pick a preset on the first run.

If you use Claude Code with a Max, Team or Enterprise subscription, run /login inside the sandbox. The session token stays on your host. When I first started it, Claude Code said "Not logged in", so expect to do this once. If you pay per API call instead, store your key on the host with sbx secret set (credential docs) rather than pasting it into the sandbox. Codex, Copilot, Cursor, Devin, Droid, Kiro, OpenCode and Docker Agent are also supported, and so is a plain shell.

From a second terminal you can see what's running and open up network access:

sbx ls
sbx policy ls
sbx policy allow network registry.npmjs.org

When the agent needs a site outside the active rules, it gets blocked and you decide whether to allow it. Balanced already permits common services, so the npm registry example may not need an extra rule. Don't approve on autopilot. Each "yes" adds to what the agent can reach.

What I saw when I tried it

I ran these checks on macOS with sbx 0.54.1 and the Balanced preset, from a shell inside the sandbox:

  • sudo whoami printed root. The agent really does get sudo inside the VM.
  • docker run --rm hello-world pulled and ran on the sandbox's own engine. docker info reported the sandbox's name, not my Mac. There is a /var/run/docker.sock inside the sandbox, but it belongs to that private engine.
  • curl -sI https://example.com got 403 Forbidden from the sandbox proxy. The site isn't on the Balanced allow-list, so it was blocked.
  • curl -sI https://registry.npmjs.org went through the proxy and returned 200.

Keep tokens out of the sandbox

If the agent needs GitHub, don't paste a token into the sandbox. Store it on the host instead:

sbx secret set github --command 'gh auth token'

The proxy adds the token to GitHub requests, so the real value never enters the VM. Be clear about what this does and doesn't do. While the agent runs, it can still use that access, for example to push to any repo the token allows. So give the token the smallest scope that works. What the agent can't do is copy the token out and reuse it somewhere else later.

Your project folder is shared by default

This is the one people miss. When you run sbx run without a path, your current folder is mounted read-write. When I tried it in a test folder, the startup summary said so plainly: Workspace: /tmp/sbx-demo (rw). Docker's workspace isolation docs say: "There is no boundary between the agent's edits and your host filesystem." The agent can change build scripts, CI files, IDE settings, agent config like .claude/settings.json, and Git hooks. Changes to .git/hooks/ don't show up in git diff.

You choose how much of your project the agent sees:

Mode How What the agent can touch
Direct mount sbx run claude in your project Your working tree, read-write, hooks included
Clone sbx run --clone claude . A private clone inside the VM; your repo is mounted read-only
Mountless sbx create --name scratch claude No host project files

For anything that runs unattended, use clone mode. Docker recommends it for unfamiliar agents and for running several agents on one repo. The agent works on its own clone. When I tried it, the startup summary still said Workspace: /tmp/sbx-demo (rw), which looks alarming but refers to the agent's clone inside the VM. The line to check is source /tmp/sbx-demo → /run/sandbox/source (ro): your repo is mounted read-only.

To get the agent's commits, run git fetch sandbox-<name> in your repo while the sandbox is running (Git workflows). Fetched branches are kept under refs/sandboxes/<name>/, so they survive sbx rm. Turn one into a normal branch with git branch my-branch refs/sandboxes/<name>/<branch>. Fetch before you remove the sandbox: sbx rm warns you, but anything you didn't fetch is lost.

One catch: clone mode stops the agent from changing your repo, not from reading it. Untracked files like .env are still readable inside the sandbox. Keep secrets out of the project folder and use sbx secret instead.

When you're done:

sbx stop my-sandbox   # keeps state
sbx rm my-sandbox     # asks to confirm; deletes the VM and everything in it, not your host files

To come back to a sandbox later, run sbx run --name my-sandbox. Running sbx on its own opens a dashboard of all your sandboxes.

Local or cloud?

The sbx CLI and local sandboxes are free, including for commercial use (docs). Since 24 September 2026 you can also run sandboxes on Docker's cloud (announcement). That's useful for long or overnight jobs, or when you want to close your laptop. Cloud sandboxes are part of Docker Agentic Platform, which Docker still labels experimental.

Cloud compute is billed per second, by sandbox size, and a stopped sandbox isn't billed. Prices can change, so I'm not listing them here: see Docker's Cloud Sandboxes announcement for the launch details and the Usage & billing page in the Agentic Platform console for current rates. Model usage is billed by your model provider, not Docker.

To use the cloud, you turn on the Docker Agentic Platform pay-as-you-go plan for your personal Docker account. It's billed separately from your regular Docker subscription. Cloud sandboxes expire after one hour by default, and you can extend that up to 24 hours from creation. Copy your work out before a sandbox expires. The cloud lifecycle docs explain what happens to stopped sandboxes.

To move a local sandbox to the cloud:

sbx move my-project --to cloud

This copies a snapshot of the sandbox's filesystem. A few things don't come with it (move docs):

  • Running processes and memory.
  • Workspace mounts and clone-mode volumes. A direct-mounted project stays on your machine, and clone-mode volumes are excluded too. Copy or commit the work you need separately.
  • Secrets from your local store, and the network rules you added locally. You set those up again on the cloud side.

The destination must support the source architecture: sbx move does not convert between Arm and x86. It creates a separate sandbox and leaves the source in place; later changes are not synchronized.

One thing does come with it. If an agent signed in from inside the sandbox and saved a credential to disk, that file goes along with the snapshot. Remove in-sandbox credentials before you move.

One current cloud limitation: docker exec, docker compose exec and healthchecks can use the sandbox VM filesystem instead of the target container's filesystem. Check the known limitations before moving a container-based test workflow.

For teams, Docker AI Governance (a separate paid product) lets admins set network, filesystem and MCP rules for everyone's local sandboxes. Org rules take priority over local ones.

What sandboxes don't protect you from

Docker's isolation docs are honest about the limits. These are the ones I'd keep in mind:

  • Direct-mount edits. The agent can edit hooks, CI config, build files and IDE tasks that run later on your host. Docker's advice is to review those changes like a pull request from someone you don't know.
  • Shared skills. Supported agents also mount a persistent host-side skills store read-only by default. A sandbox granted write access can change skills that other sandboxes load. Use --skills=off at creation if you do not want that mount.
  • Hard links. If a file in your project is a hard link to a file outside it, the agent can change the original. Filesystem rules don't catch this.
  • Local MCP servers. MCP servers that run locally over stdio run on your host, not in the VM. They are not sandboxed.
  • SSH agent and clipboard. SSH agent forwarding is on by default. Your private keys stay on the host, but anything in the sandbox can ask the agent to sign. The sandbox can also write to your clipboard, so check what you paste after running untrusted code.
  • Environment files. Sandbox environment files can run commands on your host with your permissions. sbx shows you a plan first. Read it before you approve.
  • Your allow-list. Every site you allow is a site the agent could send your data to. Keep it short.
  • Prompt injection. The sandbox limits the damage, but an agent that reads a poisoned README can still misuse whatever access you gave it.

That last point is why a sandbox doesn't replace review. It decides how bad a mistake can get, not whether the agent makes one. Anything that leaves the sandbox still needs a human to look at it first: a push to a shared branch, a production credential, a change to CI.

Where to start

  1. Stop mounting docker.sock into agent containers. If the agent needs Docker, give it a sandbox.
  2. Run sbx policy init balanced and allow only the sites your agent needs.
  3. Use clone mode (sbx run --clone claude .) for unattended runs, and keep .env files out of the project folder.
  4. Store tokens with sbx secret set and keep their scope small.
  5. After each session, check the diff and .git/hooks/ before you build or push.

References

  1. Docker, "Meet the New Docker: Built to Run on Trust" (19 Nov 2026) — https://www.docker.com/blog/meet-the-new-docker-built-to-run-on-trust/
  2. Docker Docs, "Docker Sandboxes" — https://docs.docker.com/ai/sandboxes/
  3. Docker Docs, "Install Docker Sandboxes" — https://docs.docker.com/ai/sandboxes/install/
  4. Docker Docs, "Get started with Docker Sandboxes" — https://docs.docker.com/ai/sandboxes/get-started/
  5. Docker Docs, "Default security posture" — https://docs.docker.com/ai/sandboxes/security/defaults/
  6. Docker Docs, "Isolation layers" (includes workspace isolation) — https://docs.docker.com/ai/sandboxes/security/isolation/
  7. Docker Docs, "Cloud sandboxes" — https://docs.docker.com/ai/sandboxes/cloud/
  8. Docker Docs, "Move a sandbox" — https://docs.docker.com/ai/sandboxes/cloud/move/
  9. Sekaran & Gumbley, "Why MicroVMs: The Architecture Behind Docker Sandboxes" (16 Apr 2026) — https://www.docker.com/blog/why-microvms-the-architecture-behind-docker-sandboxes/
  10. Karia & Sekaran, "Introducing Cloud Sandboxes" (24 Sep 2026) — https://www.docker.com/blog/introducing-cloud-sandboxes-start-on-your-laptop-finish-in-the-cloud/
  11. Docker Docs, "Docker daemon attack surface" — https://docs.docker.com/engine/security/#docker-daemon-attack-surface
  12. Docker Docs, "Manage credentials" — https://docs.docker.com/ai/sandboxes/configuration/credentials/
  13. Docker Docs, "Sign up for Docker Agentic Platform" — https://docs.docker.com/agentic-platform/signup/
  14. Docker Docs, "Use cloud sandboxes" — https://docs.docker.com/ai/sandboxes/cloud/usage/
  15. Docker Docs, "AI governance" — https://docs.docker.com/ai/governance/
  16. Docker Agentic Platform, "Usage & billing" (sign-in required) — https://agentic-platform.docker.com/usage
  17. Docker Docs, "Git workflows" — https://docs.docker.com/ai/sandboxes/workflows/git/

Anoop Gopi is a Docker Captain. Views are his own and not Docker's.

📰 Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.