Docker configuration to run Claude Code in a containerised environment. This project provides a restricted sandbox environment for running Claude safely, preventing access to the local machine's file system and other sensitive resources. The containerized setup ensures that Claude operations are isolated from the host system, providing an additional layer of security for development and experimentation.
Start container runtime, e.g. Colima or Docker Desktop
Colima start
colima startBuild the image
docker build -t claude-sandbox .Set up local directories and configuration
mkdir -p ~/.claude-sandbox/.claude
cp .claude.json ~/.claude-sandbox/.claude.jsonRun the container
docker run -it \
-v $(pwd):/workspace/${PWD##*/} \
-v ~/.claude-sandbox/.claude:/home/appuser/.claude \
-v ~/.claude-sandbox/.claude.json:/home/appuser/.claude.json \
--network="host" \
-w /workspace/${PWD##*/} \
claude-sandboxThis command starts the folder based on the project direct the container was started in so that you can use the same command for multiple projects and Claude will maintain separate configuration for each.
Set up shell alias go claude-box
bash alias
Add this to your ~/.bashrc or ~/.bash_profile:
alias claude-box='docker run -it \
-v $(pwd):/workspace/${PWD##*/} \
-v ~/.claude-sandbox/.claude:/home/appuser/.claude \
-v ~/.claude-sandbox/.claude.json:/home/appuser/.claude.json \
--network="host" \
-w /workspace/${PWD##*/} \
claude-sandbox'Then reload your shell configuration:
source ~/.bashrcfish alias
function claude-box
docker run -it \
-v $(pwd):/workspace/(path basename $PWD) \
-v ~/.claude-sandbox/.claude:/home/appuser/.claude \
-v ~/.claude-sandbox/.claude.json:/home/appuser/.claude.json \
-w /workspace/(path basename $PWD) \
claude-sandbox $argv
endYou can register custom commands
mkdir ~/.claude-sandbox/.claude/commands
echo "Apply precepts.md from MCP Reader" > ~/.claude-sandbox/.claude/commands/precepts.md
Add you can add MCP Servers
claude-box mcp add -s user \
--transport sse markdown-reader http://host.docker.internal:8080/sse
claude-box mcp add -s user \
--transport http context7 https://mcp.context7.com/mcp
Install pre-commit for local lint and pre-commit checks.
pip install pre-commitInstall the git hook scripts:
pre-commit installRun against all files if you need to do a full check:
pre-commit run --all-filesRemove the Docker image:
make cleanRemove image and all local directories. This will remove all session context and memory for Claude from running with this container.
make clean-all