Use claude-sandbox inside your existing devcontainer#

If you already develop inside a devcontainer, you can install the sandbox into it, so Claude works with your project’s own tools and Python environment. This tutorial takes an existing devcontainer to a working sandbox. The examples use a devcontainer generated by python-copier-template; other devcontainers need the same steps.

If you don’t use devcontainers, follow Getting started instead.

Before you start#

Your devcontainer needs to:

  • be based on Debian or Ubuntu;

  • run as root under rootless Podman, so root in the container is your own user on the host (rootful Docker is not supported);

  • have uv installed.

python-copier-template devcontainers meet all three. Without uv, use the clone fallback for step 2.

1. Give the container the network device#

The sandbox’s network jail needs the /dev/net/tun device. Add it to runArgs in .devcontainer/devcontainer.json, keeping the entries already there. In a python-copier-template project:

"runArgs": [
    // Allow the container to access the host X11 display and EPICS CA
    "--net=host",
    // Make sure SELinux does not disable with access to host filesystems like tmp
    "--security-opt=label=disable",
    // The claude-sandbox network jail needs this device
    "--device=/dev/net/tun"
]

Rebuild the container: in VS Code, run Dev Containers: Rebuild Container. This is the only change the sandbox needs in your project. Commit it, so everyone using the devcontainer has the device.

2. Install the sandbox#

In a terminal inside the devcontainer:

uvx claude-sandbox install

This installs Claude Code, Codex and Pi, each wrapped by the sandbox. If you only use Claude, run uvx claude-sandbox install --minimal to skip the other two (Claude-only installation).

3. Start Claude#

Start Claude from your project folder and log in when prompted:

claude

Claude can now change files only inside the folder you started it in.

4. Keep your login across rebuilds#

Rebuilding the devcontainer removes the sandbox, and with it your Claude login, unless the container mounts a shared config folder from your host. python-copier-template devcontainers already mount it at /user-terminal-config, so your login and Claude’s memory survive rebuilds and are shared by all your devcontainers. For other devcontainers, add the terminal-config mount.

5. Reinstall after each rebuild#

The sandbox itself still has to be reinstalled after a rebuild. Either:

  • Just for you, in every devcontainer: python-copier-template devcontainers run /user-terminal-config/bashrc in each new shell. Add uvx claude-sandbox install to its run-once section, and the sandbox installs in the first shell of each new container.

  • For everyone on the project: install a pinned release from the devcontainer’s postCreateCommand; see Sandbox a team devcontainer.

Each container still needs the /dev/net/tun device from step 1.

Next steps#