Security Isolation
Network firewall restricts external access to approved services only
Development containers provide the perfect balance between Claude Code’s powerful automation capabilities and enterprise security requirements. By isolating Claude in a containerized environment, you can safely use --dangerously-skip-permissions
for unattended operation while protecting your host system and production credentials.
Security Isolation
Network firewall restricts external access to approved services only
Consistent Environment
Identical setup across team members regardless of host OS
Permission Freedom
Skip permission prompts safely in isolated container
Quick Onboarding
New developers productive in minutes, not hours
Install prerequisites
Clone reference implementation
git clone https://github.com/anthropics/claude-code.gitcd claude-code/.devcontainer
Open in VS Code
code .
Reopen in container
Remote-Containers: Reopen in Container
Claude Code automatically installs and configures itself in the container, ready for immediate use with enhanced security.
The reference implementation consists of three core components:
{ "name": "Claude Code Dev Container", "build": { "dockerfile": "Dockerfile", "context": ".." }, "features": { "ghcr.io/devcontainers/features/node:1": { "version": "20" } }, "customizations": { "vscode": { "extensions": [ "dbaeumer.vscode-eslint", "esbenp.prettier-vscode", "ms-azuretools.vscode-docker" ], "settings": { "terminal.integrated.defaultProfile.linux": "zsh", "editor.formatOnSave": true } } }, "postCreateCommand": ".devcontainer/init-firewall.sh", "remoteUser": "vscode", "mounts": [ "source=${localEnv:HOME}/.ssh,target=/home/vscode/.ssh,type=bind,consistency=cached", "source=claude-history,target=/home/vscode/.claude,type=volume" ], "runArgs": ["--cap-add=NET_ADMIN"]}
FROM mcr.microsoft.com/devcontainers/javascript-node:20
# Install system dependenciesRUN apt-get update && apt-get install -y \ git \ zsh \ fzf \ ripgrep \ iptables \ && rm -rf /var/lib/apt/lists/*
# Configure shell enhancementsRUN sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
# Install Claude Code globallyRUN npm install -g @anthropic-ai/claude-code
# Create non-root userARG USERNAME=vscodeARG USER_UID=1000ARG USER_GID=$USER_UID
RUN groupadd --gid $USER_GID $USERNAME \ && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \ && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME
USER $USERNAME
The init-firewall.sh
script implements a strict default-deny firewall:
#!/bin/bash
# Reset firewall rulessudo iptables -Fsudo iptables -X
# Default policies: deny allsudo iptables -P INPUT DROPsudo iptables -P FORWARD DROPsudo iptables -P OUTPUT DROP
# Allow loopbacksudo iptables -A INPUT -i lo -j ACCEPTsudo iptables -A OUTPUT -o lo -j ACCEPT
# Allow established connectionssudo iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# Whitelist essential servicesALLOWED_DOMAINS=( "api.anthropic.com" # Claude API "statsig.anthropic.com" # Telemetry "registry.npmjs.org" # npm packages "github.com" # Git operations "raw.githubusercontent.com" # Raw file access)
for domain in "${ALLOWED_DOMAINS[@]}"; do # Resolve and allow each IP for ip in $(dig +short $domain A); do sudo iptables -A OUTPUT -d $ip -j ACCEPT donedone
# Allow DNS queriessudo iptables -A OUTPUT -p udp --dport 53 -j ACCEPTsudo iptables -A OUTPUT -p tcp --dport 53 -j ACCEPT
# Allow SSH for gitsudo iptables -A OUTPUT -p tcp --dport 22 -j ACCEPT
echo "✅ Firewall configured with restricted access"
Extend the Dockerfile to include your team’s standard toolset:
# Add Python development environmentRUN apt-get update && apt-get install -y \ python3 \ python3-pip \ python3-venv \ && rm -rf /var/lib/apt/lists/*
# Install common Python toolsRUN pip3 install --user \ black \ flake8 \ mypy \ pytest
# Install GoRUN curl -OL https://go.dev/dl/go1.21.linux-amd64.tar.gz \ && sudo tar -C /usr/local -xzf go1.21.linux-amd64.tar.gz \ && rm go1.21.linux-amd64.tar.gz
ENV PATH=$PATH:/usr/local/go/bin
# Install Go toolsRUN go install golang.org/x/tools/gopls@latestRUN go install github.com/go-delve/delve/cmd/dlv@latest
# Install RustRUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
ENV PATH="/home/vscode/.cargo/bin:${PATH}"
# Install additional componentsRUN rustup component add rustfmt clippy
Modify firewall rules for your organization’s needs:
# Add private registry accessPRIVATE_REGISTRY="registry.company.com"for ip in $(dig +short $PRIVATE_REGISTRY A); do sudo iptables -A OUTPUT -d $ip -j ACCEPTdone
# Add internal API accesssudo iptables -A OUTPUT -d 10.0.0.0/8 -j ACCEPT # Private networksudo iptables -A OUTPUT -d 172.16.0.0/12 -j ACCEPT # Docker networks
# Add specific ports for servicessudo iptables -A OUTPUT -p tcp --dport 5432 -j ACCEPT # PostgreSQLsudo iptables -A OUTPUT -p tcp --dport 6379 -j ACCEPT # Redis
Configure persistent storage for different scenarios:
{ "mounts": [ // SSH keys for git operations "source=${localEnv:HOME}/.ssh,target=/home/vscode/.ssh,type=bind,readonly",
// AWS credentials (if needed) "source=${localEnv:HOME}/.aws,target=/home/vscode/.aws,type=bind,readonly",
// Persistent Claude history "source=claude-history,target=/home/vscode/.claude,type=volume",
// Shared team configuration "source=${localWorkspaceFolder}/.devcontainer/team-config,target=/home/vscode/.config/team,type=bind,readonly" ]}
Configure proxy settings in the container:
# Add to DockerfileARG HTTP_PROXYARG HTTPS_PROXYARG NO_PROXY
ENV HTTP_PROXY=${HTTP_PROXY}ENV HTTPS_PROXY=${HTTPS_PROXY}ENV NO_PROXY=${NO_PROXY}
# Configure npm for proxyRUN if [ -n "$HTTP_PROXY" ]; then \ npm config set proxy $HTTP_PROXY && \ npm config set https-proxy $HTTPS_PROXY; \ fi
Share consistent Claude Code settings:
{ "permissions": { "allow": ["*"], // Safe in isolated container "deny": [] }, "env": { "CLAUDE_CODE_ENABLE_AUDIT_LOGGING": "1" }, "hooks": { "PreEdit": "npm run lint --fix", "PostEdit": "npm run format" }}
Mount and apply in postCreateCommand
:
# Copy team settingscp /home/vscode/.config/team/claude-settings.json ~/.claude/settings.json
Credential Management
Never include credentials in container images. Use volume mounts or environment variables.
Image Scanning
Regularly scan container images for vulnerabilities using tools like Trivy or Snyk.
Least Privilege
Run containers as non-root users and limit capabilities to minimum required.
Network Monitoring
Log and monitor outbound connections to detect unusual activity.
Add logging to track Claude’s actions:
# Add to init-firewall.sh# Log all accepted connectionssudo iptables -A OUTPUT -j LOG --log-prefix "CLAUDE-ALLOW: " --log-level 4
# Log all rejected connectionssudo iptables -A OUTPUT -j LOG --log-prefix "CLAUDE-DENY: " --log-level 4
View logs with:
sudo dmesg | grep CLAUDE-
Create isolated environments for different clients:
# Client A containercd ~/projects/client-acode . # Opens with client-a specific devcontainer
# Client B containercd ~/projects/client-bcode . # Completely isolated from client-a
Use devcontainers in CI/CD:
name: Claude Code Testing
on: [push, pull_request]
jobs: test: runs-on: ubuntu-latest container: image: your-registry/claude-devcontainer:latest options: --cap-add=NET_ADMIN
steps: - uses: actions/checkout@v3
- name: Run Claude Code tests run: | claude -p "Run all tests and fix any failures"
Standardize developer environments:
Create team container
FROM anthropic/claude-devcontainer:base
# Add team-specific toolsCOPY .devcontainer/team-tools.sh /tmp/RUN /tmp/team-tools.sh
Document in README
## Getting Started1. Clone this repository2. Open in VS Code3. Click "Reopen in Container"4. Run `claude` to start coding!
Everything is pre-configured - no setup required.
# Clean rebuilddocker system prune -acode . # Retry opening in container
# Check Docker resourcesdocker system df# Increase Docker Desktop memory if needed
# Test DNS resolutiondig api.anthropic.com
# Check firewall rulessudo iptables -L -n -v
# Verify allowed domains resolvefor domain in api.anthropic.com github.com; do echo "Testing $domain:" nc -zv $domain 443done
# Fix ownership issuessudo chown -R vscode:vscode /home/vscode
# Reset Claude Code permissionsrm -rf ~/.claude/settings.jsonclaude logoutclaude login
Configure container resources in Docker Desktop or docker-compose.yml
:
version: '3.8'services: devcontainer: build: . mem_limit: 8g cpus: 4 volumes: - /tmp/.X11-unix:/tmp/.X11-unix:rw
Speed up rebuilds with BuildKit cache mounts:
# Cache package downloadsRUN --mount=type=cache,target=/var/cache/apt \ apt-get update && apt-get install -y git zsh
# Cache npm packagesRUN --mount=type=cache,target=/root/.npm \ npm install -g @anthropic-ai/claude-code
CI/CD Integration
Automate workflows with Claude in your pipelines
Team Workflows
Scale devcontainer usage across your organization
Security Hardening
Advanced security configurations for containers