How to run Claude Code in a dev container with an egress firewall
Install Claude Code in a dev container and the commands Claude runs execute inside the container instead of on your machine, while file edits still show up in your local repository. On November 24, developer Milan Jovanović shared a setup that moves Claude Code into a container on a VPS, blocks outbound traffic except to Claude, GitHub and NuGet, and drives it from a phone with Remote Control. The official docs walk through it like this.
- Create
.devcontainer/devcontainer.jsonin your repository and add the Claude Code Feature.
{
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
"features": {
"ghcr.io/anthropics/devcontainer-features/claude-code:1.0": {}
}
}
-
Run Dev Containers: Rebuild Container from the VS Code Command Palette, then run
claudein the container terminal and sign in. -
To avoid signing in again after every rebuild, mount a volume at
~/.claudeand setCLAUDE_CONFIG_DIRto the same path. This example is for a container whoseremoteUserisnode.
"mounts": [
"source=claude-code-config,target=/home/node/.claude,type=volume"
],
"containerEnv": {
"CLAUDE_CONFIG_DIR": "/home/node/.claude"
}
- To restrict outbound traffic, copy the official reference container (the
.devcontainer/folder in the anthropics/claude-code repository). Itsinit-firewall.shonly allows traffic to the destinations the script lists. Running a firewall inside the container needs these capabilities inrunArgs.
"runArgs": [
"--cap-add=NET_ADMIN",
"--cap-add=NET_RAW"
]
Because the container runs Claude Code as a non-root user, you can pass --dangerously-skip-permissions for unattended runs (the CLI rejects the flag when launched as root). Claude can still modify any file in the bind-mounted workspace, and a malicious project could exfiltrate the Claude Code credentials in ~/.claude inside the container. Use it only with trusted repositories and don't mount host secrets such as ~/.ssh.
Sources
Get notified when a new tip lands
Tip alerts only go out in the app. Install it and turn notifications on.