Claude Code Docker sandbox

Dagu Docker sandbox से Claude Code चलाएं।

Claude Code को runner image में install करें, claude binary verify करें, और credentials केवल उसी harness step को दें जिसे उनकी जरूरत है। Dagu schedule, logs, retry policy और container boundary को YAML में रखता है।

Docker में Claude Code step
steps:
  - id: claude_review
    action: harness.run
    container:
      image: dagu-claude-runner:local
      pull_policy: never
      working_dir: /workspace
      volumes:
        - .:/workspace:ro
      env:
        - ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY}
    with:
      provider: claude
      model: sonnet
      prompt: |
        Review this repository and summarize the highest-risk issues.

Official @anthropic-ai/claude-code npm package use करता है।

Model calls से पहले Dagu के through claude --version verify करता है।

ANTHROPIC_API_KEY को container step boundary पर pass करता है।

Credential scope के हिसाब से root-level या step-level containers के साथ काम करता है।

01

Runner image

Claude Code को Node.js 18 या newer पर global npm package के रूप में install किया जा सकता है। Example Node 22 use करता है और image build के दौरान binary verify करता है।

Dockerfile
FROM node:22-bookworm-slim

RUN apt-get update \
  && apt-get install -y --no-install-recommends ca-certificates git ripgrep bash \
  && rm -rf /var/lib/apt/lists/*

RUN npm install -g @anthropic-ai/claude-code
RUN claude --version

WORKDIR /workspace
ENTRYPOINT []
CMD ["bash"]
02

Smoke test

पहले shell provider चलाएं ताकि Claude को prompt भेजे बिना image और binary path verify हो जाए।

Version check DAG
type: graph

harnesses:
  shell:
    binary: sh
    prefix_args:
      - -c
    prompt_mode: arg

steps:
  - id: claude_version
    action: harness.run
    container:
      image: dagu-claude-runner:local
      pull_policy: never
    with:
      provider: shell
      prompt: |
        set -eu
        claude --version
        command -v claude
03

Credentials

Simple non-interactive run के लिए ANTHROPIC_API_KEY को container में pass करें। Claude Code के दूसरे auth methods भी चल सकते हैं अगर उनकी files या environment variables उसी container में available हों।

04

Container scope

एक Claude Code task के लिए step-level container prefer करें। Root-level container तभी use करें जब build या test steps को उसी image में चलना हो और उसके बाद Claude Code workspace पढ़े।