A Beginner’s Guide to Safe, Reproducible Environments
2026-02-25
| Part | Topic | Time |
|---|---|---|
| 🐳 | What is Docker? Why a Sandbox? | 10 min |
| 💻 | Installing Docker Desktop | 10 min |
| 📦 | Building Your First Image | 15 min |
| 🏃 | Running Containers & Volumes | 15 min |
| 🤖 | Setting Up Claude Code, Codex & Gemini CLI | 15 min |
| 🔒 | Safety: Partitions & Disk Limits | 10 min |
| 🛠️ | Hands-On: Run Your First Agent | 15 min |
Companion handout: Docker Setup Guide for AI Coding Agents
An AI coding agent is not just a chatbot. It can:
Would you let a stranger do all this on your personal laptop?
Agent runs on your system.
Can access everything.
Mistakes affect YOU.
Agent runs in a container.
Cannot escape the sandbox.
Your system stays safe.
Docker = an isolated mini-computer inside your real computer.
docker buildx build (~20--30 min)docker compose up (~10 sec)
🎓 Good news: Docker Desktop is free for educational use.
Students and educators at universities can use it without any licensing concerns.
Two options for Windows users:
| Docker Desktop | Docker Engine in WSL 2 | |
|---|---|---|
| GUI | ✅ Yes | ❌ CLI only |
| Setup | Easy (installer) | Moderate (manual) |
| Best for | Beginners | Experienced users |
Mac users: Docker Desktop is the standard choice.
Step 1: Install WSL 2 (PowerShell as Admin)
Restart. Set a Linux username and password.
Step 2: Download Docker Desktop from docker.com/products/docker-desktop
Run installer, keep defaults, restart if asked.
Step 3: Configure Docker Desktop
⏱ Total: ~15 min including restarts
Step 4: Open Ubuntu (NOT PowerShell!) and run:
You should see “Hello from Docker!”
Step 5: Adjust resources in Docker Desktop → Settings → Resources:
| Setting | Recommended |
|---|---|
| CPUs | 4+ |
| Memory | 8–16 GB |
| Disk | 60+ GB |
These are upper limits — Docker only uses what it needs.
Step 1: Check your chip (Apple menu → About This Mac)
Step 2: Download Docker Desktop from docker.com/products/docker-desktop
Choose your chip type. Open .dmg, drag to Applications.
Step 3: Open Docker, grant permissions, accept agreement.
Step 4: Open Terminal and verify:
⏱ Total: ~10 min
For Windows users who prefer a lightweight, CLI-only setup:
Step 1: Install WSL 2 (same as before: wsl --install, restart)
Step 2: Open Ubuntu terminal, install Docker Engine:
Step 3: Start Docker manually each session:
⏱ ~15 min · Full step-by-step in the handout, Part 2 Option B
echo 'sudo service docker start' >> ~/.bashrc
sudo usermod -aG docker $USERdocker build, docker compose, and docker run commands work identically — Docker Desktop or Engine in WSL 2.
Docker caches every layer. Change the last layer only? Rebuild in seconds.
R packages are pre-installed in the Dockerfile — you wait once, not every time.
# Python
RUN apt-get install -y python3 python3-pip
RUN pip3 install numpy pandas matplotlib
# Node.js (needed for Codex and Gemini CLI)
RUN curl -fsSL https://deb.nodesource.com/setup_24.x | bash -
RUN apt-get install -y nodejs
# Claude Code
RUN curl -fsSL https://claude.ai/install.sh | bash
# OpenAI Codex
RUN npm install -g @openai/codex
# Google Gemini CLI
RUN npm install -g @google/gemini-cliStata is commercial software. You need a Linux license from your university, or use R equivalents (fixest, plm, rdrobust). See the handout.
The provided Dockerfile is a starting point. Want to add packages or tools?
Paste the Dockerfile into your favourite LLM and ask:
“I need to add the
sfandterraR packages for geospatial analysis. How should I modify this Dockerfile?”
LLMs are excellent at writing and debugging Dockerfiles — they know the right system libraries, dependency chains, and best practices.
~/project/ workspace/ ← shared output/ ← shared CLAUDE.md ← shared (read-only) my-photos/ ← NOT shared passwords.txt ← NOT shared
/home/agent/ project/ ← agent works here output/ ← results go here CLAUDE.md ← agent reads this (everything else is invisible to the agent)
Only explicitly mounted folders are visible. Everything else stays private.
services:
agent:
image: coding-agent
container_name: my-agent
stdin_open: true
tty: true
mem_limit: 16g # Max RAM
cpus: 4 # Max CPU cores
pids_limit: 512 # Max processes
volumes:
- ./workspace:/home/agent/project
- ./output:/home/agent/output
- ./CLAUDE.md:/home/agent/CLAUDE.md:ro
- agent-auth:/root/.claude
volumes:
agent-auth:Pay per use. You control spending via the API dashboard.
The key starts with sk-ant-... — save it somewhere safe.
Flat monthly fee. No per-token charges.
Subscribe at claude.ai (Pro $20/mo, Max $100–200/mo)
Copy URL → open in browser → log in → done. Saved in Docker volume.
Open source (Apache 2.0) — github.com/openai/codex
Get a key at platform.openai.com → API Keys
Open source (Apache 2.0) — github.com/google-gemini/gemini-cli
Get a key at aistudio.google.com → API Keys
Agent downloads 100 GB.
System drive fills up.
Computer freezes. Bad day.
Agent hits 30 GB limit.
"No space left on device".
Your system is fine.
Solution: Give Docker its own storage area with a hard size cap.
Workshop recommendation: Option A is sufficient. See handout Part 14 for Options B & C.
Mac:
Windows (WSL):
Agent fills up the 30 GB? It stops. Your system stays safe.
Mac: Docker Desktop → Settings → Resources → Disk image location → Browse → select external drive. Done.
Windows (PowerShell as Admin):
All Docker data now lives on D:\. Your C:\ drive is protected.
| Layer | Protects Against | Effort |
|---|---|---|
| Docker container | Agent escaping to your system | Built-in |
| Resource limits | RAM/CPU exhaustion | Easy |
| Volume mounts | Unwanted file access | Easy |
Read-only (:ro) |
Config file modification | Easy |
| Option A: Separate drive | Filling your system drive | Easy |
| Option B: Dedicated disk image | All Docker storage | Advanced |
| Option C: Limited workspace | Data explosion | Medium |
mkdir -p ~/coding-agent-workshopDockerfile (copy from handout Part 9)docker-compose.yml (copy from handout Part 5)docker buildx build -t coding-agent .docker compose up -ddocker exec -it my-agent bashclaude, codex, or geminiSee the handout for detailed instructions at each step.
Then type:
Write an R script that loads the mtcars dataset, runs a regression of mpg on wt and hp, and saves a nice ggplot to output/regression_plot.pdf
Watch it plan, write code, run it, see errors, fix them, and produce output.
Check output/ on your host for results!
All three agents can:
docker compose up -d # Start docker exec -it my-agent bash # Enter docker compose down # Stop docker ps # List docker stats my-agent # Monitor
claude # Claude Code claude --model opus # Opus model codex # OpenAI Codex gemini # Gemini CLI R / Rscript script.R # Run R python3 # Run Python
| Resource | Link |
|---|---|
| Workshop Materials | github.com/AlexRieber/Workshops/Docker |
| Docker Desktop | docker.com/products/docker-desktop |
| Claude Code Docs | code.claude.com/docs |
| Anthropic API Keys | platform.claude.com |
| OpenAI Codex | github.com/openai/codex |
| OpenAI API Keys | platform.openai.com |
| Google Gemini CLI | github.com/google-gemini/gemini-cli |
| Google AI Studio | aistudio.google.com |
Questions? Let's set up your first container!
Docker Setup Workshop