DEV Community

Cover image for What Are Docker Sandboxes? How Docker Isolates AI Coding Agents
Hassann
Hassann

Posted on Originally published at apidog.com

What Are Docker Sandboxes? How Docker Isolates AI Coding Agents

Docker Sandboxes: Running AI Coding Agents in Isolated microVMs

Quick answer: Docker Sandboxes run AI coding agents such as Claude Code, Codex and Cursor inside isolated microVMs, on your machine or on Docker's cloud. Each sandbox has its own kernel, filesystem, network and private Docker Engine. You drive it with the free sbx CLI, and the agent reaches only the folders and domains you allow.

Try Apidog today

On November 19, 2026, Docker relaunched its brand around one line: "Containers isolate workloads. But agents aren't workloads. Agents are actors." The rebrand post says little about the product itself. It points readers at Docker Sandboxes and Docker AI Governance, so this guide pulls the facts from Docker's docs instead.

What are Docker Sandboxes?

Docker Sandboxes are isolated microVM environments built to run autonomous AI coding agents. Each sandbox gets its own kernel, Docker daemon, filesystem and network. Inside, the agent has full privileges, including sudo. Outside, it sees only the workspace you share and the network destinations your policy allows.

You manage sandboxes with the sbx CLI, which doesn't need Docker Desktop or Docker Engine. The same CLI runs local sandboxes on your laptop and cloud sandboxes on Docker-managed compute, and sbx move carries a sandbox's filesystem between the two.

Docker's architecture page compares the approach with the usual alternatives:

Approach Isolation Docker access Best for
Docker Sandboxes (microVMs) Full (hypervisor) Isolated daemon Autonomous agents
Container with socket mount Partial (namespaces) Shared host daemon Trusted tools
Docker-in-Docker Partial (privileged) Nested daemon CI/CD pipelines
Host execution None Host daemon Manual development

The trade is resources for safety: every sandbox runs a VM plus its own daemon, and sandboxes don't share images.

How Docker Sandboxes isolate an AI agent

The microVM is the main trust boundary. Docker's security model lists five layers:

  1. Hypervisor isolation. Each sandbox has a separate kernel, with no shared memory or processes with the host.
  2. Network isolation. Outbound TCP goes through a proxy on your host under a deny-by-default policy. UDP and ICMP are blocked by default.
  3. Docker Engine isolation. The agent's containers run on a private engine with no path to your host daemon.
  4. Workspace isolation. You choose what the agent sees: nothing, a read-only repo with a private clone, or your working tree read-write.
  5. Credential isolation. API keys never enter the VM. The agent sees a sentinel value, and the host proxy swaps in the real credential after the request leaves the sandbox.

Diagram of a Docker Sandbox: the agent and its private Docker Engine inside a microVM, with only the workspace mount, the host network proxy and the MCP gateway crossing the boundary to the host

A prompt-injected agent can't print a key it never had. It can still use that key through allowed requests, so the network policy matters as much as the credential trick.

Docker is also clear about what isolation doesn't cover. In direct mode, the agent edits your real files, including Git hooks, CI config and package.json scripts that run later on your host. Git hooks don't show in git diff, so check them separately.

Which agents Docker Sandboxes support

The agents page lists these for local sandboxes:

  • Claude Code
  • Codex
  • Copilot
  • Cursor
  • Devin
  • Docker Agent
  • Droid
  • Kiro
  • OpenCode
  • Shell, an agent-less sandbox for manual setup

Each agent starts from a template image. Codex uses docker/sandbox-templates:codex, and its default startup command is codex --dangerously-bypass-approvals-and-sandbox. Docker's reasoning: the microVM, network policy and credential isolation already handle what approval prompts guard against. You can switch approvals back on inside the session.

One setup detail catches people out. Sandboxes don't import user-level config such as ~/.claude or ~/.codex, only project-level config in the working directory.

How to set up Docker Sandboxes

Local sandboxes need one of these hosts, per the install guide:

OS Requirements Install command
macOS Sonoma 14 or later, Apple silicon brew trust docker/tap && brew install docker/tap/sbx
Windows Windows 11, 64-bit Intel or AMD, Windows Hypervisor Platform on winget install -h Docker.sbx
Linux Ubuntu 24.04 or later, KVM on, user in the kvm group Docker's convenience script with SBX=1 (below)

On Ubuntu, that's curl -fsSL https://get.docker.com | sudo SBX=1 sh. Then follow the get started guide:

  1. Sign in with sbx login. Docker ties every sandbox to a verified Docker identity.
  2. Store credentials on the host. For Codex, sbx secret set openai --oauth runs the OAuth flow in your browser and keeps tokens in your OS keychain.
  3. Pick a network preset. sbx policy init balanced allows typical development traffic, including AI services and package registries. The other options are deny-all and allow-all.
  4. Run an agent from your project folder:
cd ~/my-project
sbx run --name my-sandbox claude   # or: sbx run codex
Enter fullscreen mode Exit fullscreen mode
  1. Watch it. sbx ls shows each sandbox's agent, status and workspace. Plain sbx opens a live dashboard.
  2. Clean up. sbx stop my-sandbox keeps packages and images for next time. sbx rm my-sandbox deletes everything inside it; your host working tree stays put.

Network and filesystem policy

Network policy decides where the agent can go. List the rules, then open only what the task needs:

sbx policy ls
sbx policy allow network registry.npmjs.org
sbx policy check network api.anthropic.com
Enter fullscreen mode Exit fullscreen mode

sbx policy check answers Allowed or Denied from the active policy, so you can confirm a boundary before the agent starts. Docker warns that the default allow list includes broad wildcards such as *.googleapis.com. Prune what you don't need.

Filesystem exposure is set when you create the sandbox:

  • Direct mount (the sbx run default): your project folder appears at the same absolute path, read-write.
  • Clone mode (--clone): your repo is mounted read-only and the agent works on a private clone. Good for several agents on one repo.
  • Mountless (sbx create without a path): nothing from your host is shared.

For repeatable team setups, a kit bundles an agent's tools, credentials, network rules and config in one YAML file.

Docker Sandboxes pricing

Docker's FAQ says the sbx CLI and local sandbox compute are free, including for commercial work. Model-provider charges are separate.

Cloud sandboxes need a Docker Agentic Platform subscription and are metered by the second. The Docker Sandboxes product page listed these rates on November 20, 2026:

Size vCPUs Memory Per hour
Micro 1 2 GB $0.07
Small 2 4 GB $0.14
Medium 4 8 GB $0.28
Large 8 16 GB $0.56
XL 16 32 GB $1.12

Cloud sandboxes expire after one hour by default and can't mount a host folder. Organization governance is a separate paid subscription sold through Docker Sales.

Docker AI Governance and the MCP Enterprise Gateway

Docker AI Governance is the team layer on top of sandboxes. Docker's November 18 post splits it into three parts:

  • Sandbox policies: allow or block domains, IP ranges and ports, and control which host paths can be mounted. Enforcement happens at the proxy and mount layers, not in the agent.
  • MCP tool governance: admins decide which MCP servers can be registered and which tool calls agents may make. Policies are written in Cedar, and governed requests are denied unless a policy permits them.
  • Audit and visibility: a record of each policy decision (principal, action, target, decision, time) that can feed a SIEM. Records hold metadata, not prompts.

Here's the Cedar example from that post, permitting read-only tool calls on one server:

permit (principal, action == MCP::Action::"invokeTool", resource)
when {
  resource in MCP::Server::"example" &&
  resource.readOnly == true
};
Enter fullscreen mode Exit fullscreen mode

When organization governance is on, local sbx policy allow rules stop counting; local deny rules still apply.

Diagram of Docker AI Governance: an admin console pushes sandbox network and filesystem policies, MCP tool policies and audit logging to every developer's local sandboxes

The MCP piece comes in two sizes. Every sandbox has a local MCP gateway: register a server once with sbx mcp add notion --url https://mcp.notion.com/mcp, then expose it to one sandbox with --static-mcp notion. Local stdio servers run on the host, not in the VM, so treat them as trusted host code. For organizations, Docker sells the MCP Enterprise Gateway, which approves servers, scopes tools to groups and logs every call.

One boundary to remember: an agent that calls a remote MCP server directly from inside a sandbox falls under network policy, not MCP policy.

Test an API from inside a Docker Sandbox with Apidog CLI

A sandbox lets your agent change code without risk to your laptop. It still has to prove the change works against a real API. Apidog CLI gives it commands for test cases and runs, with JSON output it can read.

Check that the sandbox can reach Apidog and your API, and allow them if denied:

sbx policy check network api.apidog.com
sbx policy allow network api.apidog.com
sbx policy allow network api.example.com
Enter fullscreen mode Exit fullscreen mode

Then install and sign in inside the sandbox:

sbx exec -it my-sandbox bash
npm install -g apidog-cli@latest
apidog auth login --with-token <YOUR_TOKEN>
apidog skill install
Enter fullscreen mode Exit fullscreen mode

Apidog isn't one of the services sbx secret set injects, so this token lives inside the VM. Use one you can revoke, and sbx rm the sandbox when you're done.

Give your agent one prompt:

Using Apidog CLI, create a test case in project <projectId> for
POST /orders on endpoint <endpointId> that asserts a 201 status and an
"id" field in the body. Run it against environment <envId> and
summarize any failures.
Enter fullscreen mode Exit fullscreen mode

The agent reads the payload schema, validates its file and runs the case:

apidog cli-schema get test-case-create
apidog cli-schema validate test-case-create --file case.json
apidog test-case create --project <projectId> --file case.json
apidog test-case run --project <projectId> --endpoint <endpointId> -e <envId> -r cli,json
Enter fullscreen mode Exit fullscreen mode

A network error usually means the allow list missed a host: the sandbox doing its job. For agent-specific setup, see Apidog CLI in Claude Code or Apidog CLI in Codex, and swap -r cli,json for -r junit in a CI pipeline. Apidog's Free plan covers up to 4 users.

Prefer to keep Codex on your host? Our guide to the Codex sandbox covers that route, and CubeSandbox is another isolation option built for agents.

FAQ

Are Docker Sandboxes just containers? No. They're microVMs with a separate kernel per sandbox. Each runs its own Docker Engine, so the agent can build containers without touching your host daemon.

Are Docker Sandboxes free? The sbx CLI and local compute are free, including for commercial work. Cloud sandboxes start at $0.07 an hour, model charges are separate, and organization governance costs extra.

Do I need Docker Desktop? No. The sbx CLI installs on its own through Homebrew, WinGet or Docker's Ubuntu packages.

Can the agent see my API keys? Not for services sbx manages, such as OpenAI, Anthropic and GitHub. The host proxy injects those credentials, and the raw values never enter the VM. Anything you install inside the sandbox yourself does live there.

Why does Codex run with approvals off in a sandbox? sbx run codex starts codex --dangerously-bypass-approvals-and-sandbox by default, because the microVM is the safety boundary. You can turn approval prompts back on inside the session.

Top comments (0)