# Claude Code Sandbox vs Dev Container: Which One on a VPS?

> On Ubuntu 24.04 the Claude Code sandbox turned itself off and ran the command anyway. Use a dev container to run Claude Code unattended on a VPS.

Published: 2026-11-20. Author: Milan Jovanović.

Canonical: https://milanjovanovic.tech/blog/claude-code-sandbox-vs-dev-container

Use a **dev container** to run Claude Code unattended on a VPS.
The built-in sandbox only wraps shell commands, so file tools, MCP servers, and hooks run outside it.
On Ubuntu 24.04 it stays off until you add an AppArmor profile.
The separate `srt` runtime wraps the whole process, but it is still a beta.

I turned on the sandbox on a stock Ubuntu 24.04 server.
Claude Code printed a warning and ran the command anyway:

![Terminal on the host. Claude Code runs a prompt with the sandbox enabled in settings, prints a warning that the sandbox is disabled because Ubuntu](https://milanjovanovic.tech/blogs/articles/claude-code-sandbox-vs-dev-container/sandbox_disabled.png)

In print mode (`claude -p`, which runs one prompt and exits), that warning is the only sign.

I tested on a 2 vCPU / 8 GB Ubuntu 24.04 VPS with Docker 29.10 on November 20, 2026, with Claude Code 2.1.328 on the host and 2.1.329 in the container.
I didn't test a VM, Claude Code inside `srt`, or whether the AppArmor fix survives a reboot.
[**The complete dev container**](https://milanjovanovic.tech/code/claude-code-devcontainer.zip) is based on Anthropic's [**reference container**](https://github.com/anthropics/claude-code/tree/main/.devcontainer), with a non-root user and a firewall that blocks every host you haven't allowed.

## What Is the Difference Between a Claude Code Dev Container and the Sandbox?

- **Built-in sandbox**: on Linux, [**Claude Code**](https://code.claude.com/docs/en/overview) runs each shell command inside bubblewrap, which gives it private views of the filesystem and network.
- **Sandbox runtime (`srt`)**: the same engine as a separate command that wraps the whole Claude Code process.
- **Dev container**: a Docker container defined in your repo's `.devcontainer` folder, with everything Claude starts inside it.

![A grid comparing the built-in sandbox, srt, and a dev container. Shell commands are inside all three. Read, Write and Edit tools, MCP servers and hooks are outside the built-in sandbox but inside srt and the dev container. With dangerously-skip-permissions, new web hosts are allowed by the built-in sandbox, blocked unless listed by srt, and blocked unless the IP is listed by the dev container. The host home folder and ssh keys are readable in the sandbox, readable unless denied in srt, and not mounted in the dev container. On Ubuntu 24.04 the sandbox turns itself off, srt needs an AppArmor profile, and the dev container works.](https://milanjovanovic.tech/blogs/articles/claude-code-sandbox-vs-dev-container/boundary_coverage.png)

The [**sandboxing docs**](https://code.claude.com/docs/en/sandboxing) confirm the built-in sandbox column.
MCP servers (programs that give Claude extra tools) and hooks (commands Claude Code runs at set points) stay outside the built-in sandbox.

## Why Does Claude Code Say Sandbox Disabled on Ubuntu 24.04?

Ubuntu 24.04 uses AppArmor, its Linux security module, to stop ordinary programs from creating user namespaces, the isolated spaces that bubblewrap builds.
Bubblewrap needs them.
To reproduce it, install two packages and turn the sandbox on in `.claude/settings.json`:

```bash
sudo apt-get install -y -qq bubblewrap socat
```

```json
{
  "sandbox": { "enabled": true, "autoAllowBashIfSandboxed": true }
}
```

`autoAllowBashIfSandboxed` lets sandboxed commands run without a prompt, and its default changed to `false` in v2.1.324.

The narrow fix from the docs is an AppArmor profile that lets only `/usr/bin/bwrap` create user namespaces:

```bash
sudo tee /etc/apparmor.d/bwrap > /dev/null <<'EOF'
abi <abi/4.0>,
include <tunables/global>

profile bwrap /usr/bin/bwrap flags=(unconfined) {
  userns,

  include if exists <local/bwrap>
}
EOF
sudo apparmor_parser -r /etc/apparmor.d/bwrap
```

The same `bwrap` test failed before the profile and passed after it:

![Terminal on the host. The sysctl setting kernel.apparmor_restrict_unprivileged_userns is 1, and bwrap fails with Failed RTM_NEWADDR, exit 1. After root loads the AppArmor profile for bwrap, the same bwrap command exits 0.](https://milanjovanovic.tech/blogs/articles/claude-code-sandbox-vs-dev-container/bwrap_apparmor.png)

The `sysctl` command in the warning lifts the restriction for every program until reboot.
The docs suggest it when `which bwrap` points somewhere other than `/usr/bin/bwrap`.
They also say `sandbox.failIfUnavailable: true` makes Claude Code stop instead of running unsandboxed.

## Is the Claude Code Sandbox Enough for dangerously-skip-permissions?

No.
With the sandbox working, I gave Claude five steps in print mode.
In the default mode, the proxy denied `curl` and the Write tool stopped at the permission check.
With `--dangerously-skip-permissions`, both got through:

![Terminal on the host with the sandbox on and permissions skipped. A Bash write to the home folder fails with Read-only file system, curl to example.com returns 200, and the Write tool creates /home/agent/outside-write.txt. An ls afterwards shows the Write tool file exists on the host and the Bash file does not.](https://milanjovanovic.tech/blogs/articles/claude-code-sandbox-vs-dev-container/skip_permissions_write.png)

The Write tool wrote where Bash couldn't, because file tools run outside the sandbox.
The [**settings reference**](https://code.claude.com/docs/en/settings-reference) explains the `200`: in `bypassPermissions` mode the proxy allows hosts outside your allowed domains, unless `sandbox.network.strictAllowlist` is `true` in user or managed settings.

Both runs could read `~/.ssh`, and neither could use the Docker socket.
Inside the dev container, the firewall refused `example.com`, and my home folder and the Docker socket didn't exist.

## Does the Claude Code Sandbox Work Inside Docker?

Not in the dev container I tested.
Without bubblewrap, Claude Code warned and ran the command unsandboxed.
With bubblewrap installed, it couldn't create a namespace under Docker's default seccomp (system call filter) and AppArmor profiles, and Claude Code refused to retry outside the sandbox.
The container's firewall already covers every process in it, so the sandbox adds little.

## What Is the Claude Code Sandbox Runtime?

[**`srt`**](https://github.com/anthropics/sandbox-runtime) is the open source engine behind the built-in sandbox, published as `@anthropic-ai/sandbox-runtime`.
The [**sandbox environments page**](https://code.claude.com/docs/en/sandbox-environments) lists the whole Claude Code process as inside it, including file tools, MCP servers, and hooks.
Anthropic calls it a beta research preview.

I ran version 0.0.83 on the host.
Without the AppArmor profile it exited with the same `RTM_NEWADDR` error instead of running the command.
With the profile, `~/.srt-settings.json` allowed one domain and writes to the current folder, and hid `~/.ssh`:

```json
{
  "network": { "allowedDomains": ["example.com"], "deniedDomains": [] },
  "filesystem": { "denyRead": ["~/.ssh"], "allowWrite": ["."], "denyWrite": [] }
}
```

![Terminal on the host running srt with the settings file. curl to example.com returns 200, curl to api.github.com fails with response 403, the write to the home folder fails with Read-only file system, ssh keys are not found, and docker ps is denied.](https://milanjovanovic.tech/blogs/articles/claude-code-sandbox-vs-dev-container/srt_allowlist.png)

The write to the current folder worked.
Pass the command as separate words, as in `bash -c '...'`, because one quoted string failed with `No such file or directory`.
To wrap Claude Code, the docs run `srt claude` with `claude.ai` and `platform.claude.com` on the allowlist for login.
Inside `srt`, the agent still runs as your user, with your server's tools.

## Should I Use the Claude Code Sandbox or a Dev Container?

Use the dev container for unattended runs.
It has its own non-root user, which you need anyway, because [**`--dangerously-skip-permissions` refuses to run as root**](https://milanjovanovic.tech/blog/claude-code-dangerously-skip-permissions).
Your home folder, SSH keys, and the Docker socket stay outside unless you mount them.
The docs say to run sessions that skip permissions inside a container, a VM, or the sandbox runtime, and that a VM gives the strongest separation.

The container has gaps too.
The agent can send its login token to any host [**the firewall**](https://milanjovanovic.tech/blog/claude-code-devcontainer-firewall) allows.
It can also write [**git hooks**](https://milanjovanovic.tech/blog/devcontainer-git-hooks-escape) that run on the host when you commit there.
[**The Dev Containers CLI guide**](https://milanjovanovic.tech/blog/claude-code-devcontainer-cli) covers the setup without VS Code.

Keep the built-in sandbox for interactive work, where you answer the prompts.
To undo the host changes from this guide:

```bash
sudo apparmor_parser -R /etc/apparmor.d/bwrap
sudo rm -f /etc/apparmor.d/bwrap
sudo apt-get purge -y bubblewrap socat
rm -f ~/.srt-settings.json
```

## Summary

The built-in sandbox wraps only shell commands, and on a stock Ubuntu 24.04 server it turned itself off.
With permissions skipped, the Write tool and `curl` both got past it.
`srt` followed its settings file, but it is still a beta and runs as your own user.
For unattended runs on a VPS, put Claude Code in a dev container with a non-root user and a firewall, and mount only the repo.

My [**self-hosting course**](https://milanjovanovic.tech/pragmatic-self-hosting) covers setting up and securing the VPS these containers run on.

Thanks for reading.

And stay awesome!

---

## Frequently asked questions

### Should I use the Claude Code sandbox or a dev container?

For unattended runs on a VPS, use a dev container. The built-in sandbox only wraps shell commands, so file tools, MCP servers, and hooks run outside it. With permissions skipped, it also let a shell command reach a host that was on no allowlist.

### Is the Claude Code sandbox enough for dangerously-skip-permissions?

No. In testing with the sandbox on and permissions skipped, curl reached example.com and the Write tool created a file in the home folder, outside the project. The Claude Code docs also say the sandboxed Bash tool on its own is not enough for unattended runs.

### Why does Claude Code say Sandbox disabled on Ubuntu 24.04?

Ubuntu 24.04 restricts unprivileged user namespaces through AppArmor, and bubblewrap needs them. Claude Code prints a warning and runs commands without the sandbox. An AppArmor profile for /usr/bin/bwrap fixed it in testing.

### Does the Claude Code sandbox work inside Docker?

Not in the dev container I tested. With bubblewrap installed, it could not create a new namespace under Docker default security settings. Without bubblewrap, Claude Code warned and ran commands without the sandbox.

### What is the Claude Code sandbox runtime?

It is the open source engine behind the built-in sandbox, packaged as a command called srt. It wraps a whole process, including Claude Code file tools, MCP servers, and hooks. Anthropic calls it a beta research preview.
