Last active
May 13, 2026 12:36
-
-
Save megahertz/5d213f5e5ba4d4de7a95494621d8e734 to your computer and use it in GitHub Desktop.
There's a `docker sandbox run claude` command, but it requires Docker Desktop to be installed, which is pretty undesirable on Linux since it replaces Docker Engine with a VM environment. This simple script does similar things.
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 | |
| set -e | |
| image='docker-claude' | |
| docker_args=() | |
| case "$1" in | |
| -h|--help) | |
| echo 'Usage: docker-claude [options] [command] [prompt]' | |
| echo 'docker-claude commands:' | |
| echo ' update [docker-build-flags] Pull latest image and update packages' | |
| echo ' env FILE Run claude with environment variables loaded from FILE' | |
| echo '' | |
| echo ' cat Run the CMD in container' | |
| echo ' cp ...' | |
| echo ' ls ...' | |
| echo ' npm ...' | |
| echo ' pnpm ...' | |
| echo ' sh ...' | |
| echo '' | |
| echo 'Original claude help:' | |
| echo '' | |
| set -- claude --help | |
| ;; | |
| cat|cp|ls|npm|pnpm|sh) ;; | |
| env) | |
| if [ -z "$2" ]; then | |
| echo 'docker-claude: env requires an ENV_PATH argument' >&2 | |
| exit 1 | |
| fi | |
| if [ ! -f "$2" ]; then | |
| echo "docker-claude: env file not found: $2" >&2 | |
| exit 1 | |
| fi | |
| docker_args+=(--env-file "$2") | |
| shift 2 | |
| set -- claude --dangerously-skip-permissions "$@" | |
| ;; | |
| update) | |
| shift | |
| docker build --pull "$@" -t "${image}" - <<EOF | |
| FROM node:24 | |
| RUN usermod -l agent -d /home/agent -m node && groupmod -n agent node | |
| RUN ln -sfn /home/agent /home/$(id -un) | |
| RUN apt-get update \ | |
| && apt-get install -y --no-install-recommends jq \ | |
| && rm -rf /var/lib/apt/lists/* | |
| RUN npm i -g @anthropic-ai/claude-code pnpm | |
| USER agent | |
| WORKDIR /home/agent | |
| EOF | |
| echo 'Claude code was updated' | |
| set -- claude --version | |
| ;; | |
| *) set -- claude --dangerously-skip-permissions "$@" ;; | |
| esac | |
| if ! docker image inspect "${image}" >/dev/null 2>&1; then | |
| "$0" update | |
| fi | |
| docker run --init -it --rm \ | |
| "${docker_args[@]}" \ | |
| -v "$(pwd):$(pwd)" -w "$(pwd)" \ | |
| -v "${HOME}/.claude:/home/agent/.claude" \ | |
| -v "${HOME}/.agents:/home/agent/.agents" \ | |
| -v "${HOME}/.claude.json:/home/agent/.claude.json" \ | |
| -e GIT_AUTHOR_NAME="$(git config user.name)" \ | |
| -e GIT_AUTHOR_EMAIL="$(git config user.email)" \ | |
| -e TERM=xterm-256color \ | |
| -e COLORTERM=truecolor \ | |
| "${image}" "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment