Created
April 12, 2026 12:13
-
-
Save alexsavio/71709ab412bc9542df3f39e314ff269b to your computer and use it in GitHub Desktop.
claude-sandbox — run Claude Code in an isolated Docker container with no permission prompts (uses your existing subscription via setup-token)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # claude-sandbox — run Claude Code in an isolated container (uses your subscription) | |
| # | |
| # Usage: | |
| # claude-sandbox "implement feature X" # pipe mode (non-interactive) | |
| # claude-sandbox # interactive mode | |
| # | |
| # First run: prompts you to create a long-lived token via `claude setup-token`. | |
| # Token is cached in ~/.claude-sandbox-token for subsequent runs. | |
| set -euo pipefail | |
| IMAGE="claude-sandbox" | |
| TOKEN_FILE="$HOME/.claude-sandbox-token" | |
| PROJECT_DIR="$(git rev-parse --show-toplevel 2>/dev/null || pwd)" | |
| # --- Token setup (first run only) --- | |
| if [ ! -f "$TOKEN_FILE" ]; then | |
| echo "No sandbox token found. Running 'claude setup-token' to create one..." >&2 | |
| echo "This only happens once." >&2 | |
| echo "" >&2 | |
| claude setup-token | |
| echo "" >&2 | |
| read -rp "Paste the token here: " token | |
| if [ -z "$token" ]; then | |
| echo "Error: no token provided." >&2 | |
| exit 1 | |
| fi | |
| echo "$token" > "$TOKEN_FILE" | |
| chmod 600 "$TOKEN_FILE" | |
| echo "Token saved to $TOKEN_FILE" >&2 | |
| fi | |
| OAUTH_TOKEN="$(cat "$TOKEN_FILE")" | |
| # --- Build image (first run only, cached) --- | |
| if ! docker image inspect "$IMAGE" &>/dev/null; then | |
| echo "Building $IMAGE image (first run only)..." >&2 | |
| docker build -t "$IMAGE" - <<'DOCKERFILE' | |
| FROM node:22-slim | |
| RUN npm i -g @anthropic-ai/claude-code@latest | |
| RUN mkdir -p /home/node/.claude \ | |
| && cat <<'SETTINGS' > /home/node/.claude/settings.json | |
| { | |
| "permissions": { | |
| "allow": [ | |
| "Bash(*)", | |
| "Read(*)", | |
| "Write(*)", | |
| "Edit(*)", | |
| "Glob(*)", | |
| "Grep(*)" | |
| ], | |
| "deny": [] | |
| } | |
| } | |
| SETTINGS | |
| RUN chown -R node:node /home/node/.claude | |
| USER node | |
| WORKDIR /work | |
| DOCKERFILE | |
| fi | |
| # --- Run --- | |
| if [ $# -gt 0 ]; then | |
| docker run --rm -it \ | |
| -v "$PROJECT_DIR":/work \ | |
| -e CLAUDE_CODE_OAUTH_TOKEN="$OAUTH_TOKEN" \ | |
| "$IMAGE" \ | |
| claude -p "$*" --permission-mode bypassPermissions | |
| else | |
| docker run --rm -it \ | |
| -v "$PROJECT_DIR":/work \ | |
| -e CLAUDE_CODE_OAUTH_TOKEN="$OAUTH_TOKEN" \ | |
| "$IMAGE" \ | |
| claude --permission-mode bypassPermissions | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment