This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is the Claude Code Sandbox project - a CLI tool that runs Claude Code instances inside isolated Docker containers with automatic git integration. The tool creates safe sandboxed environments where Claude can execute commands and make code changes without affecting the host system.
npm run build- Compile TypeScript to JavaScript (output indist/)npm run dev- Watch mode for TypeScript compilationnpm start- Run the CLI tool
npm run lint- Run ESLint on TypeScript filesnpm test- Run Jest tests
npm run purge-containers- Remove all Claude Sandbox containers and images
-
CLI Entry Point (
src/cli.ts)- Command-line interface using Commander.js
- Handles options parsing and main flow orchestration
-
Container Management (
src/container.ts)- Docker container lifecycle management using dockerode
- Builds images, creates containers, handles streams
- Manages volume mounts for credentials and workspace
-
Git Integration (
src/git-monitor.ts)- Monitors git repository for new commits
- Uses simple-git for operations
- Provides real-time notifications of Claude's commits
-
Credential Discovery (
src/credentials.ts)- Automatically discovers Claude API keys (Anthropic, AWS Bedrock, Google Vertex)
- Discovers GitHub credentials (CLI auth, SSH keys)
- Mounts credentials read-only into containers
-
Configuration (
src/config.ts)- Loads and validates configuration from
claude-sandbox.config.json - Manages Docker settings, environment variables, and Claude parameters
- Loads and validates configuration from
-
UI Components (
src/ui.ts)- Interactive prompts using inquirer
- Diff display with syntax highlighting
- Commit review interface
- Claude runs with
--dangerously-skip-permissionsflag (safe within container isolation) - Git wrapper prevents branch switching to protect main branch
- All credentials are mounted read-only
- Each session creates a new branch (
claude/[timestamp]) - Real-time commit monitoring with interactive review
The shadow repository maintains a real-time sync with the container's workspace using the following principles:
- Git-tracked files take precedence: Any file that is committed to the git repository will be synced to the shadow repo, regardless of whether it matches patterns in
.gitignore - Gitignore patterns apply to untracked files: Files that are not committed to git but match
.gitignorepatterns will be excluded from sync - Built-in exclusions: Certain directories (
.git,node_modules,__pycache__, etc.) are always excluded for performance and safety - Rsync rule order: Include rules for git-tracked files are processed before exclude rules, ensuring committed files are always preserved
This ensures that important data files (like corpora, model files, etc.) that are committed to the repository are never accidentally deleted during sync operations, even if they match common gitignore patterns like *.zip or *.tar.gz.
The tool looks for claude-sandbox.config.json in the working directory. Key options:
dockerImage: Base image namedockerfile: Path to custom Dockerfileenvironment: Additional environment variablesvolumes: Additional volume mountsallowedTools: Claude tool permissions (default: all)autoPush/autoCreatePR: Git workflow settings
Start a new sandbox:
claude-sandbox start
Kill all running sandbox containers:
claude-sandbox purge -y