Created
March 7, 2026 20:09
-
-
Save thimslugga/6e0191425219685e2a387196c5f485be to your computer and use it in GitHub Desktop.
Claude Code Sandbox
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
| #!/bin/bash | |
| # Build | |
| podman build -t claude-code . | |
| # Run against current dir, reusing your local auth session | |
| podman run -it --rm \ | |
| -v ~/.claude:/home/coder/.claude:z \ | |
| -v "$(pwd)":/workspace:z \ | |
| claude-code | |
| # Or pass the API key directly | |
| podman run -it --rm \ | |
| -e ANTHROPIC_API_KEY="sk-ant-..." \ | |
| -v "$(pwd)":/workspace:z \ | |
| claude-code |
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
| services: | |
| claude: | |
| build: | |
| context: . | |
| dockerfile: Dockerfile | |
| stdin_open: true | |
| tty: true | |
| init: true | |
| environment: | |
| TERM: xterm-256color | |
| CLAUDE_CONFIG_DIR: "/claude" | |
| DATABASE_URL: "postgresql://user:password@db:5432/db" | |
| REDIS_URL: "redis://redis:6379/0" | |
| profiles: | |
| - claude | |
| volumes: | |
| - .:/app | |
| - ./.claude-credentials:/claude |
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
| FROM ubuntu:24.04 | |
| ENV DEBIAN_FRONTEND=noninteractive | |
| ENV PYTHONDONTWRITEBYTECODE=1 | |
| ENV PYTHONUNBUFFERED=1 | |
| RUN \ | |
| apt-get update \ | |
| && apt-get install -y \ | |
| bubblewrap \ | |
| socat \ | |
| nodejs \ | |
| npm \ | |
| libvips-dev \ | |
| && rm -rf /var/lib/apt/lists/* ; \ | |
| npm install -g @anthropic-ai/claude-code ; | |
| WORKDIR /app | |
| CMD ["bash"] |
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
| FROM node:24-alpine | |
| COPY entrypoint.sh /usr/local/bin/entrypoint.sh | |
| RUN \ | |
| apk add --no-cache \ | |
| bash \ | |
| git \ | |
| su-exec \ | |
| && npm install -g @anthropic-ai/claude-code@~2.1.0 ; \ | |
| chmod +x /usr/local/bin/entrypoint.sh ; \ | |
| mkdir -p /{claude,workspace} ; | |
| WORKDIR /workspace | |
| ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] | |
| CMD ["sh", "-c", "echo 'Claude Code container is ready!'"] |
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
| # syntax=docker/dockerfile:1 | |
| FROM fedora:43 | |
| LABEL \ | |
| org.opencontainers.image.title="claude-code" \ | |
| org.opencontainers.image.description="Claude Code on Fedora" \ | |
| org.opencontainers.image.source="https://docs.anthropic.com/en/docs/claude-code/overview" | |
| RUN \ | |
| dnf install -y --setopt=install_weak_deps=False \ | |
| git \ | |
| ripgrep \ | |
| nodejs \ | |
| npm \ | |
| curl \ | |
| procps \ | |
| ca-certificates \ | |
| && dnf clean all \ | |
| && rm -rf /var/cache/dnf ; \ | |
| useradd -m -s /bin/bash -u 1000 claude | |
| USER claude | |
| WORKDIR /home/claude | |
| ENV PATH="/home/claude/.local/bin:${PATH}" | |
| ENV PATH="/home/claude/.npm-global/bin:${PATH}" | |
| RUN \ | |
| curl -fsSL https://claude.ai/install.sh | bash | |
| WORKDIR /workspace | |
| VOLUME ["/home/claude/.claude"] | |
| ENV ANTHROPIC_API_KEY="" | |
| RUN claude --version | |
| ENTRYPOINT ["claude"] |
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
| #!/bin/sh | |
| set -e | |
| # Entrypoint script for Claude Code container | |
| # Handles dynamic UID/GID mapping to match host user | |
| # Default to user 1000:1000 if not specified | |
| USER_UID=${USER_UID:-1000} | |
| USER_GID=${USER_GID:-1000} | |
| # If running as root (UID 0), stay as root | |
| if [ "$USER_UID" -eq 0 ]; then | |
| exec "$@" | |
| fi | |
| # Create group if it doesn't exist | |
| # First check if GID is already in use | |
| if ! getent group "$USER_GID" >/dev/null 2>&1; then | |
| addgroup -g "$USER_GID" claude 2>/dev/null || true | |
| else | |
| # If GID exists but not with name 'claude', use existing group | |
| EXISTING_GROUP=$(getent group "$USER_GID" | cut -d: -f1) | |
| if [ -n "$EXISTING_GROUP" ] && [ "$EXISTING_GROUP" != "claude" ]; then | |
| GROUP_NAME="$EXISTING_GROUP" | |
| else | |
| GROUP_NAME="claude" | |
| fi | |
| fi | |
| # Default group name if not set | |
| GROUP_NAME=${GROUP_NAME:-claude} | |
| # Create user if it doesn't exist | |
| # First check if UID is already in use | |
| if ! getent passwd "$USER_UID" >/dev/null 2>&1; then | |
| adduser -D -u "$USER_UID" -G "$GROUP_NAME" -h /home/claude -s /bin/sh claude 2>/dev/null || true | |
| USER_NAME="claude" | |
| else | |
| # If UID exists, use existing user | |
| USER_NAME=$(getent passwd "$USER_UID" | cut -d: -f1) | |
| fi | |
| # Ensure config directory is accessible without modifying existing credential files | |
| # Only fix ownership of the directory itself, not its contents | |
| if [ -d /claude ]; then | |
| # Change ownership of the directory itself | |
| chown "$USER_UID:$USER_GID" /claude 2>/dev/null || true | |
| # Ensure it is writeable | |
| chmod 755 /claude 2>/dev/null || true | |
| fi | |
| # Do not recursively chown workspace - files created by the container will automatically | |
| # have the correct ownership since we're running as USER_UID:USER_GID | |
| # Only ensure the directory itself is accessible | |
| if [ -d /workspace ]; then | |
| chmod 755 /workspace 2>/dev/null || true | |
| fi | |
| # Switch to the user and execute the command | |
| # Use the actual username to ensure proper environment setup | |
| # Set SHELL environment variable for Claude Code | |
| export SHELL=/bin/bash | |
| exec su-exec "${USER_NAME}" "$@" |
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
| #!/bin/bash | |
| case "$1" in | |
| continue) | |
| docker compose -f compose.yml run --rm claude script -q -c "claude --continue" /dev/null | |
| ;; | |
| *) | |
| docker compose -f compose.yml run --rm claude script -q -c claude /dev/null | |
| ;; | |
| esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment