Run Claude Code inside a Docker container

Posted on 18 June 2025

Since Claude Code can execute arbitrary shell commands it's a good idea to run it isolated from the rest of the computer.

On a mac, assuming you have homebrew already installed:

  1. Install docker / colima in case you haven't it already

brew install colima docker

brew services start colima

colima start --arch aarch64 --cpu 2 --memory 4 --disk 100

  1. Create a debian bookworm instance

docker pull debian:bookworm

docker run -it --name debian-sandbox --hostname debian-sandbox --restart unless-stopped -v ~/Documents/ai-coding:/mnt/ai-coding debian:bookworm bash

  1. Start the Sandbox

docker start -ai debian-sandbox

  1. Connect to a running sandbox

docker exec -it debian-sandbox bash

  1. Stop the Sandbox

docker stop -ai debian-sandbox