Run claude, codex, or pi in a docker container.
iptables is used inside the container to block all outbound traffic except GitHub, Anthropic, and Google Cloud internal IPs.
- docker
- Need to pass
--cap-add=NET_ADMIN --cap-add=NET_RAWto thedocker runcommand for this image to configure the firewall
- Need to pass
- You will need to mount the codebase you want to work on inside the container
- To persist your auth and settings for gemini and claude, you'll want to mount those directories into
/home/node(see usage below)
CODE_CLI=claude
cd /path/to/codebase
docker run \
-v $HOME/.$CODE_CLI:/home/node/.$CODE_CLI \
--cap-add=NET_ADMIN --cap-add=NET_RAW \
-v ./:/workspace \
-w /workspace \
--rm -it \
ghcr.io/libops/cli-sandbox:main \
"$CODE_CLI"
# chit chatThe image ships the Docker CLI, so you can drive the host's Docker daemon from inside the sandbox by bind-mounting the daemon socket.
The container runs as the unprivileged node user, and access to
/var/run/docker.sock is controlled by the group that owns it. That
group's numeric GID varies by host and rarely matches any group inside the
image, so grant it explicitly at launch with --group-add.
Detect the GID the way the container will see it — by reading it from a throwaway container that mounts the socket. This works the same on Linux, Docker Desktop, and Colima (where the daemon, and the real socket, live inside a VM rather than on your host filesystem):
SOCK_GID=$(docker run --rm -v /var/run/docker.sock:/var/run/docker.sock \
alpine stat -c %g /var/run/docker.sock)
docker run \
--cap-add=NET_ADMIN --cap-add=NET_RAW \
-v /var/run/docker.sock:/var/run/docker.sock \
--group-add "$SOCK_GID" \
-v ./:/workspace \
-w /workspace \
--rm -it \
ghcr.io/libops/cli-sandbox:main \
claude--group-add adds the socket's GID to node's supplementary groups at
container start, so docker ps works immediately — no entrypoint changes and
no editing the socket (which is typically mounted read-only). Inside the
container, verify with docker ps.
Notes:
- This grants the container full control of the host Docker daemon, which is effectively root on the host. Only do this for trusted workloads.
- Don't use the host's
statto find the GID: macOSstatuses-f %g(not-c %g), and under Colima/var/run/docker.sockdoesn't exist on the host at all — it's inside the VM. The throwaway-container command above sidesteps both problems by reading the GID from where the daemon actually runs.
With the following in your shell's dot file, you can
cd path/to/code
gemini
And you’ll get dropped into a sandbox’d docker container with the respective CLI with firewall protection and no host filesystem access besides the claude/gemini settings dir and the codebase mounted into the container. Be sure to uninstall claude or gemini from your machine to avoid conflicts.
ccli() {
if [ "$#" != 1 ]; then
echo "Need to pass gemini or claude"
return
fi
local cli=$1
if [ "$cli" != "codex" ] && [ "$cli" != "claude" ] && [ "$cli" != "pi" ]; then
echo "Need to pass claude, codex, or pi"
return
fi
if [ "$(pwd)" = "$HOME" ]; then
echo "You should cd into your codebase"
echo "Running this command here would mount your entire home directory into $cli"
return
fi
local git_name=$(git config --global user.name)
local git_email=$(git config --global user.email)
docker run \
-v $HOME/.$cli:/home/node/.$cli \
--cap-add=NET_ADMIN --cap-add=NET_RAW \
-e COLUMNS=$(tput cols) \
-e LINES=$(tput lines) \
-e GIT_AUTHOR_NAME="$git_name" \
-e GIT_AUTHOR_EMAIL="$git_email" \
-e GIT_COMMITTER_NAME="$git_name" \
-e GIT_COMMITTER_EMAIL="$git_email" \
-v ./:/workspace \
-w /workspace \
--rm -it \
ghcr.io/libops/cli-sandbox:main \
"$cli"
}
claude() {
ccli claude
}
codex() {
ccli codex
}
pi() {
ccli pi
}Dockerfileandinit-firewall.shforked from anthropics/claude-code. Added gemini support and installedgo. Also changed the firewall to allow access to google internal IPsdownload.shcopied from islandora-devops/isle-buildkit