Repository navigation
Add Docker container setup for running Claude Code safely #4139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
maliberty
merged 2 commits into
The-OpenROAD-Project:master
from
The-OpenROAD-Project-staging:claude-docker
Apr 13, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,158 @@ | ||
| #!/usr/bin/env bash | ||
| # Wrapper to run Claude Code inside a Docker container with | ||
| # --dangerously-skip-permissions. The repo is volume-mounted so all | ||
| # edits are reflected on the host. | ||
| # | ||
| # Usage: | ||
| # ./claude.sh --build # build the Docker image (one-time) | ||
| # ./claude.sh # start Claude Code interactively | ||
| # ./claude.sh --shell # get a bash shell instead | ||
| # ./claude.sh -- -p "prompt" # pass extra args to claude | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
|
|
||
| # --- Defaults (overridable via environment) --- | ||
| CLAUDE_IMAGE="${CLAUDE_IMAGE:-openroad/flow-claude:latest}" | ||
| CONTAINER_NAME="${CONTAINER_NAME:-claude-orfs}" | ||
|
|
||
| # --- Argument parsing --- | ||
| SHELL_MODE=0 | ||
| BUILD_IMAGE=0 | ||
| CLAUDE_ARGS=() | ||
|
|
||
| usage() { | ||
| cat <<EOF | ||
| Usage: $0 [OPTIONS] [-- CLAUDE_ARGS...] | ||
| Options: | ||
| --build Build the Docker image | ||
| --shell Start a bash shell instead of Claude Code | ||
| --image NAME Override Docker image (default: ${CLAUDE_IMAGE}) | ||
| --name NAME Override container name (default: ${CONTAINER_NAME}) | ||
| -h, --help Show this help | ||
| Environment: | ||
| CLAUDE_IMAGE Docker image override (same as --image). | ||
| CONTAINER_NAME Container name override (same as --name). | ||
| ANTHROPIC_API_KEY Optional. Passed through if set. | ||
| Examples: | ||
| $0 --build # build the image | ||
| $0 # interactive Claude Code | ||
| $0 -- -p "fix the floorplan" # Claude with a prompt | ||
| $0 --shell # bash inside the container | ||
| EOF | ||
| exit 0 | ||
| } | ||
|
|
||
| while [[ $# -gt 0 ]]; do | ||
| case "$1" in | ||
| --build) BUILD_IMAGE=1; shift ;; | ||
| --shell) SHELL_MODE=1; shift ;; | ||
| --image) CLAUDE_IMAGE="$2"; shift 2 ;; | ||
| --name) CONTAINER_NAME="$2"; shift 2 ;; | ||
| -h|--help) usage ;; | ||
| --) shift; CLAUDE_ARGS=("$@"); break ;; | ||
| *) CLAUDE_ARGS+=("$1"); shift ;; | ||
| esac | ||
| done | ||
|
|
||
| # --- Build image (explicitly or automatically if missing) --- | ||
| _build_image() { | ||
| echo "Building Claude Code Docker image: ${CLAUDE_IMAGE}" | ||
| docker build \ | ||
| -f "${SCRIPT_DIR}/docker/Dockerfile.claude" \ | ||
| -t "${CLAUDE_IMAGE}" \ | ||
| "${SCRIPT_DIR}/docker" | ||
| echo "Done. Image: ${CLAUDE_IMAGE}" | ||
| } | ||
|
|
||
| if [[ "${BUILD_IMAGE}" -eq 1 ]]; then | ||
| _build_image | ||
| # If only --build was given, exit. | ||
| if [[ "${SHELL_MODE}" -eq 0 ]] && [[ ${#CLAUDE_ARGS[@]} -eq 0 ]]; then | ||
| exit 0 | ||
| fi | ||
| elif ! docker image inspect "${CLAUDE_IMAGE}" > /dev/null 2>&1; then | ||
| echo "Image ${CLAUDE_IMAGE} not found. Building automatically..." | ||
| _build_image | ||
| fi | ||
|
|
||
| # --- Determine the user's home inside the container --- | ||
| # The entrypoint creates /home/claude-user for the mapped user. | ||
| CONTAINER_HOME="/home/claude-user" | ||
|
|
||
| # --- Assemble docker run arguments --- | ||
| DOCKER_RUN_ARGS=( | ||
| --rm | ||
| --name "${CONTAINER_NAME}" | ||
| -v "${SCRIPT_DIR}:/workspace" | ||
| -e "HOST_UID=$(id -u)" | ||
| -e "HOST_GID=$(id -g)" | ||
| -w /workspace | ||
| ) | ||
|
|
||
| # TTY/stdin handling for interactive, CI, and piped-input cases: | ||
| # * terminal in + terminal out → -it (normal interactive use) | ||
| # * anything else → -i (pass stdin through; no TTY) | ||
| # Forcing -it unconditionally breaks non-interactive use | ||
| # ("cannot attach stdin to a TTY-enabled container"), and dropping -i | ||
| # would silently discard piped input like `cat prompt.txt | claude.sh ...`. | ||
| if [[ -t 0 && -t 1 ]]; then | ||
| DOCKER_RUN_ARGS+=(-it) | ||
| else | ||
| DOCKER_RUN_ARGS+=(-i) | ||
| fi | ||
|
|
||
| # Pass through optional environment variables | ||
| for var in ANTHROPIC_API_KEY ANTHROPIC_MODEL CLAUDE_CODE_MAX_TURNS \ | ||
| CLAUDE_CODE_USE_BEDROCK \ | ||
| AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_REGION \ | ||
| GOOGLE_APPLICATION_CREDENTIALS; do | ||
| if [[ -v "$var" ]] && [[ -n "${!var}" ]]; then | ||
| DOCKER_RUN_ARGS+=(-e "${var}=${!var}") | ||
| fi | ||
| done | ||
|
|
||
| # SSH agent forwarding (for git push/pull over SSH) | ||
| if [[ -n "${SSH_AUTH_SOCK:-}" ]]; then | ||
| DOCKER_RUN_ARGS+=( | ||
| -v "${SSH_AUTH_SOCK}:/tmp/ssh-agent.sock" | ||
| -e "SSH_AUTH_SOCK=/tmp/ssh-agent.sock" | ||
| ) | ||
| fi | ||
|
|
||
| # Host gitconfig (read-only, for user.name / user.email) | ||
| if [[ -f "${HOME}/.gitconfig" ]]; then | ||
| DOCKER_RUN_ARGS+=(-v "${HOME}/.gitconfig:${CONTAINER_HOME}/.gitconfig:ro") | ||
| fi | ||
|
|
||
| # Persist Claude Code settings / history / memory across runs | ||
| CLAUDE_CONFIG_DIR="${HOME}/.claude" | ||
| mkdir -p "${CLAUDE_CONFIG_DIR}" | ||
| DOCKER_RUN_ARGS+=(-v "${CLAUDE_CONFIG_DIR}:${CONTAINER_HOME}/.claude") | ||
|
|
||
| # Claude Code config file (lives next to ~/.claude/, not inside it) | ||
| if [[ -f "${HOME}/.claude.json" ]]; then | ||
| DOCKER_RUN_ARGS+=(-v "${HOME}/.claude.json:${CONTAINER_HOME}/.claude.json") | ||
| fi | ||
|
|
||
| # Persist Bazel cache (avoids re-downloading hundreds of MB each run) | ||
| BAZEL_CACHE_DIR="${BAZEL_CACHE_DIR:-${HOME}/.cache/bazel-claude}" | ||
| mkdir -p "${BAZEL_CACHE_DIR}" | ||
| DOCKER_RUN_ARGS+=(-v "${BAZEL_CACHE_DIR}:${CONTAINER_HOME}/.cache/bazel") | ||
|
|
||
| # --- Run --- | ||
| if [[ "${SHELL_MODE}" -eq 1 ]]; then | ||
| exec docker run \ | ||
| "${DOCKER_RUN_ARGS[@]}" \ | ||
| "${CLAUDE_IMAGE}" \ | ||
| bash | ||
| else | ||
| exec docker run \ | ||
| "${DOCKER_RUN_ARGS[@]}" \ | ||
| "${CLAUDE_IMAGE}" \ | ||
| claude --dangerously-skip-permissions "${CLAUDE_ARGS[@]}" | ||
| fi |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| # Docker image for running Claude Code with --dangerously-skip-permissions | ||
| # inside a container that can build/test OpenROAD (CMake + Bazel) and run ORFS. | ||
| # | ||
| # Usage: see claude.sh at the repo root. | ||
|
|
||
| ARG fromImage=openroad/flow-ubuntu22.04-dev:latest | ||
|
|
||
| FROM ${fromImage} | ||
|
|
||
| # --- Bazel support --- | ||
|
|
||
| # Java 21 (required by Bazel 8.x) | ||
| RUN apt-get update \ | ||
| && apt-get install -y --no-install-recommends openjdk-21-jre-headless \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| # Bazelisk (respects .bazelversion to download the correct Bazel release) | ||
| RUN curl -Lo /usr/local/bin/bazelisk \ | ||
| https://github.com/bazelbuild/bazelisk/releases/latest/download/bazelisk-linux-amd64 \ | ||
| && chmod +x /usr/local/bin/bazelisk \ | ||
| && ln -sf /usr/local/bin/bazelisk /usr/local/bin/bazel | ||
|
|
||
| # --- Claude Code support --- | ||
|
|
||
| # Node.js 22 LTS (Claude Code requires Node 18+) | ||
| RUN curl -fsSL https://deb.nodesource.com/setup_22.x | bash - \ | ||
| && apt-get install -y --no-install-recommends nodejs \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| # Claude Code CLI | ||
| RUN npm install -g @anthropic-ai/claude-code | ||
|
|
||
| # --- Convenience --- | ||
|
|
||
| RUN apt-get update \ | ||
| && apt-get install -y --no-install-recommends \ | ||
| sudo \ | ||
| less \ | ||
| jq \ | ||
| ripgrep \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| # VS Code CLI (code-tunnel for remote editing). | ||
| # Use the glibc build to match the Ubuntu base image. (The cli-alpine-x64 | ||
| # variant on code.visualstudio.com is statically linked and also works, | ||
| # but the linux-x64 build from update.code.visualstudio.com is the | ||
| # canonical match for glibc distros.) | ||
| RUN curl -fsSL "https://update.code.visualstudio.com/latest/cli-linux-x64/stable" \ | ||
| -o /tmp/vscode-cli.tar.gz \ | ||
| && tar -xzf /tmp/vscode-cli.tar.gz -C /usr/local/bin \ | ||
| && rm /tmp/vscode-cli.tar.gz | ||
|
|
||
| # Trust all directories (safe inside container; the container IS the boundary) | ||
| RUN git config --system safe.directory '*' | ||
|
|
||
| # Entrypoint that maps host UID/GID then drops privileges | ||
| COPY claude-entrypoint.sh /usr/local/bin/claude-entrypoint.sh | ||
| RUN chmod +x /usr/local/bin/claude-entrypoint.sh | ||
|
|
||
| WORKDIR /workspace | ||
| ENTRYPOINT ["claude-entrypoint.sh"] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| #!/usr/bin/env bash | ||
| # Entrypoint for the Claude Code container. | ||
| # Creates a user matching the host UID/GID so that files created | ||
| # inside the container have the correct ownership on the host volume. | ||
| set -e | ||
|
|
||
| if [ -n "${HOST_UID}" ] && [ -n "${HOST_GID}" ]; then | ||
| USER_NAME="claude-user" | ||
| USER_HOME="/home/${USER_NAME}" | ||
|
|
||
| # Create group (reuse existing if GID is taken) | ||
| if ! getent group "${HOST_GID}" > /dev/null 2>&1; then | ||
| groupadd --gid "${HOST_GID}" "${USER_NAME}" | ||
| fi | ||
| GROUP_NAME=$(getent group "${HOST_GID}" | cut -d: -f1) | ||
|
|
||
| # Create user (reuse existing if UID is taken) | ||
| if ! getent passwd "${HOST_UID}" > /dev/null 2>&1; then | ||
| mkdir -p "${USER_HOME}" | ||
| useradd \ | ||
| --uid "${HOST_UID}" \ | ||
| --gid "${HOST_GID}" \ | ||
| --groups sudo \ | ||
| --no-create-home \ | ||
| --home-dir "${USER_HOME}" \ | ||
| --shell /bin/bash \ | ||
| "${USER_NAME}" | ||
| else | ||
| USER_NAME=$(getent passwd "${HOST_UID}" | cut -d: -f1) | ||
| USER_HOME=$(getent passwd "${HOST_UID}" | cut -d: -f6) | ||
| fi | ||
|
|
||
| # Passwordless sudo | ||
| echo "${USER_NAME} ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/claude-user | ||
| chmod 0440 /etc/sudoers.d/claude-user | ||
|
|
||
| export HOME="${USER_HOME}" | ||
| chown "${HOST_UID}:${HOST_GID}" "${USER_HOME}" | ||
| touch "${USER_HOME}/.hushlogin" | ||
|
|
||
| # Set up ORFS environment (PATH to tools, FLOW_HOME, etc.) | ||
| # Sourced here; inherited through setpriv into all child processes. | ||
| if [ -f /workspace/env.sh ]; then | ||
| set +e | ||
| . /workspace/env.sh > /dev/null | ||
| set -e | ||
|
maliberty marked this conversation as resolved.
Resolved
|
||
| fi | ||
|
maliberty marked this conversation as resolved.
Resolved
|
||
|
|
||
| exec setpriv \ | ||
| --reuid "${HOST_UID}" \ | ||
| --regid "${HOST_GID}" \ | ||
| --init-groups \ | ||
| -- "$@" | ||
| else | ||
| # No UID/GID mapping requested; run as root | ||
| if [ -f /workspace/env.sh ]; then | ||
| set +e | ||
| . /workspace/env.sh > /dev/null | ||
| set -e | ||
|
maliberty marked this conversation as resolved.
Resolved
|
||
| fi | ||
| exec "$@" | ||
| fi | ||
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.