Local agent sandboxes with docker

A local Docker Sandboxes (sbx) walkthrough with a broken FastAPI + Postgres app, and why microVMs plus a private Docker Engine fit laptop agent workflows.

dbox · docker · agents · sandboxes

Docker Sandboxes (sbx) are primarily a developer tool for your laptop: an agent execution layer you can trust by design when coding agents install packages, edit files, and run Compose on a machine you care about. Cloud sandboxes exist too, but the job I care about here is local — several repos, multiple agents, one developer machine.

I expect that pattern to get denser, not rarer. If each agent sat in a full traditional VM, a swarm on a laptop gets expensive fast, so the microVM bet makes sense: a separate kernel with less traditional VM overhead. The private Docker Engine is the other half — you cannot realistically audit that none of those agents reaches for the host Docker socket, and that socket is effectively control of the host’s containers (and, in practice, a path to the host). A container alone is the wrong default for this threat model: agents run untrusted dependencies and generated scripts; shared-kernel isolation is a weaker story for “I’ll let this run while I look away.” Even aside from malice, separate kernels and Engines are good hygiene — cleanup with sbx rm, less collision with your real local Docker state, a clear place for network policy.

Below is a thin walkthrough of that surface: install the CLI, define a sandbox and mount a project, start it with a baked-in Claude agent, and fix a small broken FastAPI + Postgres app. Repo: github.com/mkarots/dbox.

What Docker Sandboxes are

From the docs:

Docker Sandboxes run AI coding agents in isolated environments on your machine or on Docker-managed cloud infrastructure. Use the sbx CLI to create and manage either kind of sandbox.

This post is about the local path. In practice that means a microVM, a private Docker Engine, and a network policy.

a) microVM. Each sandbox gets its own lightweight microVM with a separate Linux kernel. That is the main difference from a normal container, which shares the host kernel. Processes inside the VM are invisible to the host and to other sandboxes; when you sbx rm, the VM and everything in it go away.

b) private Docker Engine. Agents often need docker / docker compose. Giving them the host Docker socket is effectively root on the host. Sandboxes avoid that path: each microVM runs its own Engine, so build / compose / run stay inside the VM and have no path to your host daemon (Isolation: Docker Engine).

c) network policy. Outbound TCP from the sandbox goes through a proxy on the host. You allow or block destinations (package registries, git hosts, model APIs, and so on). More on that when we configure the preset below.

The playground project

dbox is a playground shaped for that surface. Layout:

dbox/
├── sbx/
│   └── sbxenv.yaml    # sandbox definition — outside the mount
└── playground/        # what the agent can see and edit
    ├── TASK.md
    ├── app/
    ├── docker-compose.yml
    └── tests/

sbxenv.yaml can declare lifecycle and secret commands that sbx runs on your Mac, as your user, after you approve a plan (docs). playground/ is mounted read-write into the VM, so the agent can change any file under it.

Note: If sbxenv.yaml lived inside playground/, the agent could edit those host-side commands (or the workspace and port mappings) on disk before the next sbx env run. Keep the env file under sbx/, outside the mount: the agent can patch the notes API; it cannot rewrite the file that tells sbx what to execute on the host.

The mounted project is a simple note-keeping API: FastAPI talking to Postgres, two Compose services (api and postgres). A user can create a note, fetch it by id, and hit /health.

The stack is intentionally broken in a few places. Inside sbx, an agent should fix it with small patches, then prove:

  1. pytest passes
  2. docker compose up --build -d comes up
  3. /health sees the database
  4. create + get a note works over HTTP

The full prompt lives in the repo as playground/TASK.md. Point the agent at that file; you do not need to paste it into the chat by hand.

Optional: on the host, run make install && make test from the repo root. Schema tests should pass; two API contract tests should fail until the bugs are fixed.

Install the CLI

On macOS:

brew trust docker/tap
brew install docker/tap/sbx
sbx login
sbx --version

sbx login starts the device flow. After that you should see something like:

sbx version v0.54.0 4bec4a5ce093466e54b034146965b143d065dc09

Define and configure environment

By default sandboxes do not get open internet. Docker ships three presets:

PresetBehavior
OpenBroad egress (least locked down)
BalancedSensible defaults for coding agents
Locked DownDeny by default; you allow hosts as needed

For this walkthrough, use balanced:

sbx policy init balanced

That allows common developer destinations (package registries, git hosts, model APIs, and similar).

An environment can be defined using a configuration file: sbx/sbxenv.yaml

schemaVersion: "1"
name: dbox-notes
agent: claude
workspace: ../playground

env:
  APP_NAME: notes-api

ports:
  - sandbox: 8000
    host: 8000

What this file is doing:

  • name: dbox-notes — sandbox name you will see in sbx ls
  • agent: claude — uses the Claude kit (change to another supported agent if you prefer)
  • workspace: ../playground — host folder the agent can see and edit (sbxenv.yaml stays outside this mount so the agent cannot rewrite host-side plan commands)
  • port 8000 → 8000 — when the agent brings the API up inside the microVM, you can reach it from the host

Run the sandbox (interactively)

From sbx/:

cd sbx
sbx env plan
sbx env run

sbx env run reads the env file, shows a plan, and asks for approval. On a first run you should see it create a sandbox, env vars, and the port mapping — something like:

ENVIRONMENT
  Name:  dbox-notes
  File:  …/dbox/sbx/sbxenv.yaml

SANDBOX
  + dbox-notes
      agent: claude

WORKSPACES
  ! …/dbox/playground — present, not recorded as applied, needs your approval

ENV
  + APP_NAME
      value: notes-api

PORTS
  + 8000/tcp4
      host: 8000

  3 to add · 0 to change · 0 to destroy · 1 needs approval

Approve this plan? (y/N) y

After you approve, sbx pulls the agent kit image and drops you into an interactive session. You should see the sandbox name, the Claude kit, the mounted workspace, and port 8000 published on 127.0.0.1:8000.

Ask the agent to fix the app

In the session:

Read TASK.md and complete it.

What “done” looked like for me

The agent listed the tree, patched three bugs, ran pytest (8 passed), brought Compose up, and verified health + create/get. Edits showed up on the host immediately because of the direct mount — git diff under playground/ is the review surface.

You do not need the full transcript. The success criteria are the four goals in TASK.md.

Verify from the host

In another terminal on the Mac:

curl -s http://localhost:8000/health
curl -s -X POST http://localhost:8000/notes \
  -H 'content-type: application/json' \
  -d '{"title":"sandbox","body":"hello from sbx"}'
curl -s http://localhost:8000/notes/1

You want health with "database":"up", a POST that returns a note with an id, and a GET that returns the same note.

Example from my run:

{"status":"ok","database":"up"}
{"id":2,"title":"sandbox","body":"hello from sbx","created_at":"2026-11-22T00:34:19.027105Z"}
{"id":1,"title":"sandbox","body":"hello from sbx","created_at":"2026-11-21T23:49:38.267252Z"}

(Ids may differ depending on how many notes you created.)

Closing

The notes-API example is only important as a general coding task. A developer, runs multiple similar tasks daily, giving agents increasing autonomy over those tasks. Its important that developers can run powerful and autonomous agents, while at the same time ensuring that those powerful agents can never execute commands that will compromise or corrupt the developer’s machine.

Lastly, as an engineer, it’s nice seeing Docker Inc. working on agentic primitives, given the company’s contributions to open source software!

If you made it all the way here, feel free to send me a message on michaelk (@cepstrum9) on X with your thoughts or feedback!

References

  1. Docker Sandboxes vs containers
  2. Docker Sandboxes docs
  3. Get started
  4. Environment files
  5. Isolation
  6. Shell (agent-less sandbox)
  7. Build an agent workload (kits)
  8. mkarots/dbox