Claude Code is at its best when you let it work on its own. It can write code, run tests, build images and fix what breaks, all without you watching every step. But the moment you let an agent run any command it likes, a fair question comes up: what else on your machine can it reach?
In this post, I walk through how to run Claude Code inside a Docker Sandbox (sbx). We will look at how the sandbox works, what I found when I tested its limits, and a simple setup you can use for unattended tasks. Each section below explains one slide from my talk.
The question: how much of your computer should an agent touch?

There are two ways to run a coding agent today.
Approve every command. Claude asks before it runs anything. You stay in control of each step. The cost is that long tasks keep stopping to wait for you. If you step away for coffee, the agent sits idle.
Skip the prompts. Claude finishes the task on its own. This is much faster, but now you need a limit on what it can reach. Without one, an agent that can run rm, curl or git push has the same access you do.
Docker Sandboxes gives you that limit. Claude runs inside a microVM with controlled access to your project and to the network. You get the speed of “skip the prompts” with a clear wall around the agent.
A sandbox has its own kernel

This is the most important idea in the whole post, so it is worth slowing down.
On the left is an ordinary container setup. Container A and Container B both run on the same host kernel. The kernel is the part of the operating system that manages processes, memory and hardware. Sharing it is fine for normal apps. It is also why containers start so fast.
But for an agent that runs any command it wants, a shared kernel is a thinner wall. If something breaks out of a container, it lands on the kernel that your whole machine uses.
On the right is a Docker Sandbox. Claude Code runs on its own Linux kernel inside a microVM. It even has sudo. But sudo inside the sandbox only makes Claude root inside that small VM. It is not admin on your Mac.
So the answer to “why a VM and not just a container?” is simple: a VM gives the agent its own kernel, and that makes the boundary much stronger.
What Claude can reach

This slide is the map of the sandbox. Let’s go through it piece by piece.
Inside the microVM:
- Claude Code runs with
--dangerously-skip-permissionsandsudo. That sounds scary, but both only apply inside the VM. - Private files. Any tools and packages Claude installs live inside the sandbox. They do not touch your Mac.
- Inner Docker. The sandbox has its own Docker Engine. It is separate from Docker on your Mac. Claude can build and run containers without seeing yours.
- All of this is kept until you remove the sandbox, so you can stop and resume work later.
Connections to your Mac:
- Workspace mount. Your project folder is shared with the sandbox. In direct mode it is read and write. In clone mode it is read only.
- Policy proxy. All outbound traffic goes through a proxy that allows or blocks each destination. The proxy also adds your API keys to requests, so the keys never sit inside the VM.
- No direct path. Claude has no way to reach files you did not share, processes on your Mac, or your host Docker Engine.
Two project modes

When you create a sandbox, you pick how it sees your project.
Direct mode. Claude edits your real folder.
- Edits show up in your editor right away.
- Deletes happen right away too.
- When you review, check
.git/hooks, not justgit diff. More on that below.
Clone mode. Claude edits a copy inside the sandbox.
- Your folder stays unchanged.
- It needs a Git repo with at least one commit.
- You
fetchClaude’s work and review it before you merge.
Direct mode is handy when you are sitting with the agent and want to see changes live. Clone mode is the safer choice when you are not watching.
What the tests showed

I did not want to just trust the diagram, so I ran a set of tests. Here is what happened.
What worked well:
- Finished a task alone. Claude added a
/healthendpoint and a test, built an image, and got 3 out of 3 tests passing. No approvals needed. - Clone mode held. Deletes and commits stayed in the copy. The original folder did not change.
- Unshared stays hidden. Claude could not read a file in a folder that was not shared with the sandbox.
What needs your attention:
git diffmissed a hook. In direct mode, Claude created a new Git hook in.git/hooks. It did not show up ingit diff, because Git does not track that folder. A hook like this would run the next time you commit on your Mac.- Project files are readable. In both modes, Claude could read every file inside the project folder.
- Allowed hosts get data. A test server that was on the allow list received a value that Claude read from the project.
None of these are bugs in the sandbox. They are the sandbox doing exactly what it was told. But they show where you still need to think.
The key lesson: read only is not the same as secret

If you take one thing from this post, take this.
If Claude can read a file, and the network allows a destination, the contents of that file can leave.
Clone mode makes your folder read only for the agent. That protects your files from changes. It does not protect them from being read. And the network policy decides where Claude can connect. It does not check what Claude sends there.
So the real protection comes from two things working together: keep secrets out of the folder, and keep the allow list small.
Install sbx and sign in

Now for the hands-on part. Install sbx with Homebrew:
brew trust docker/tap
brew install docker/tap/sbx
sbx login
sbx version
If you use an Anthropic API key, store it as a sandbox secret:
sbx secret set anthropic
A few notes:
- No Docker Desktop needed. I tested this with sbx v0.43.0 on an Apple silicon Mac running macOS 14 or later.
- Have a Claude subscription? Skip the secret and type
/logininside Claude instead. - Never put your API key in a
.envfile inside the project. As we saw above, Claude can read anything in the project folder.
Choose the network access Claude needs

Next, pick a network policy. There are three presets, from more open to more locked:
- Open. Broad outbound access to the internet.
- Balanced. Model APIs and package registries are allowed. Everything else is denied. This is where you should start.
- Locked Down. Nothing is allowed until you add rules.
Set it up with:
sbx policy init balanced
These rules apply across all your sandboxes. Balanced is a good default because Claude can still talk to the model and install packages from npm or PyPI, but it cannot send data to a random server.
Start Claude in your project

Four steps to get Claude running:
Step 1. Go to the project.
cd /path/to/your/project
Step 2. Create the sandbox (pick one mode).
# direct mode
sbx create --name my-project --skills=off claude .
# clone mode
sbx create --name my-project --clone --skills=off claude .
Step 3. Check the rules.
sbx policy ls my-project --wide
Step 4. Run Claude.
sbx run --name my-project
Two things to know. The mode is set when you create the sandbox, so you cannot switch later. And --skills=off keeps the shared skills store out of this sandbox, which keeps the setup clean and predictable.
Review the work before you use it

In clone mode, Claude’s work stays in the sandbox until you pull it out. The flow looks like this:
Step 1. Claude commits on a branch inside the sandbox copy.
Step 2. Fetch that branch to your machine:
git fetch sandbox-my-project sandbox/health-check
Step 3. Read the diff:
git diff HEAD FETCH_HEAD
Step 4. Merge through your usual Git process.
Two warnings:
- Direct mode: changes are already on disk. Check
.git/hooksas well as the code. - Clone mode gives you a review step, not safe code. Read build scripts too, such as
Makefile,package.jsonscripts and Dockerfiles. A change there can run on your machine the next time you build.
Keep unrelated secrets out of reach

Files. Look at the project tree on the left. The .env file is readable by Claude even if Git ignores it. .gitignore hides files from Git, not from Claude. Move any credentials the task does not need out of the folder before you start.
Network. A policy rule controls where Claude connects, not what it sends. You can block a host, test a rule and watch the log:
sbx policy deny network --sandbox my-project example.com
sbx policy check network --sandbox my-project example.com
sbx policy log
sbx policy log is very useful. It shows every connection Claude tried, so you can see what was allowed and what was blocked.
Open the app in your browser

Say Claude builds a web app and runs it in a container on port 8000. That container runs in the sandbox’s Docker, not yours. So it will not show up in docker ps on your Mac.
To reach it, publish the port from the sandbox to your Mac:
sbx ports my-project --publish 8080:8000
open http://localhost:8080
The path is: app container :8000 → sandbox :8000 → your Mac localhost:8080. Claude publishes the port inside the sandbox, and you decide when to expose it to your machine.
Stop, resume, remove

A sandbox has a simple life cycle:
sbx stop my-project # files, tools and Docker state are kept
sbx run --name my-project # pick up where you left off
sbx rm my-project # deletes everything inside the sandbox
One important warning: in clone mode, fetch your branches before you run sbx rm. Once the sandbox is gone, so is any work you did not pull out. In direct mode, changes are already on your Mac, so they stay.
Wrap up: a checklist for unattended tasks

If you want to let Claude work while you are away, here is the checklist I use:
- Use clone mode. Nothing reaches your folder until you merge.
- Remove extra credentials. Anything in the project folder is readable.
- Start from Balanced. Allow only the destinations the task needs.
- Review before you apply. Read the diff, the hooks and the test results.
Docker Sandboxes gives Claude Code a real boundary: its own kernel, its own Docker, and a proxy that decides where traffic can go. That boundary lets you skip the approval prompts with confidence. But the sandbox can only protect what you keep out of it. Keep secrets out of the folder, keep the allow list short, and always review before you merge.
Happy sandboxing!