Skip to content

feat: add container isolation example with guard hook#30692

Open
zeitlinger wants to merge 7 commits intoanthropics:mainfrom
zeitlinger:feat/container-example
Open

feat: add container isolation example with guard hook#30692
zeitlinger wants to merge 7 commits intoanthropics:mainfrom
zeitlinger:feat/container-example

Conversation

@zeitlinger
Copy link

Summary

Adds examples/container/ with a complete setup for running Claude Code inside a Podman/Docker container instead of the built-in sandbox.

  • guard-destructive-git — PreToolUse hook that catches force push, hard reset, branch -D, rm -rf, and PR merges. Works standalone without a container — useful on its own as a safety net.
  • Dockerfile — Minimal Ubuntu 24.04 base with git and build tools. Host binaries (claude, gh) mounted at runtime.
  • claude-wrapper.sh — Wrapper script that launches Claude in a rootless Podman container with --cap-drop=ALL, --security-opt=no-new-privileges, read-only settings overlay, and settings.local.json blocked via /dev/null.
  • settings.container.json — Template container settings with guard hook pre-wired.
  • container-rules.md — Context rules injected so Claude knows it's in a container.
  • README.md — Quick start (guard-only and full container), security model, customization, tool manager integration tips.

Test plan

  • Copy files to ~/.claude/docker/ and ~/.claude/bin/, run claude — verify container starts
  • Verify guard hook standalone: echo '{"tool_input":{"command":"git push --force"}}' | ./guard-destructive-git returns "permissionDecision": "ask"
  • Verify settings overlay: inside container, settings.json shows container settings, settings.local.json is empty
  • Verify --cap-drop=ALL and --security-opt=no-new-privileges are applied (inspect with podman inspect)

Add examples/container/ with a complete setup for running Claude Code
inside a Podman/Docker container instead of the built-in sandbox.

Includes:
- guard-destructive-git: PreToolUse hook that catches force push, hard
  reset, branch -D, rm -rf, and PR merges (works standalone, no
  container needed)
- Dockerfile: minimal Ubuntu 24.04 base with build tools
- claude-wrapper.sh: wrapper that launches Claude in a rootless Podman
  container with security hardening (cap-drop=ALL, no-new-privileges,
  read-only settings overlay)
- settings.container.json: template with guard hook pre-wired
- container-rules.md: context rules injected so Claude knows it's
  running in a container
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
- guard-destructive-git: add set -euo pipefail, fail closed with ask
  decision when jq is missing or JSON parse fails
- claude-wrapper.sh: error out early if only Docker is found (uses
  Podman-specific --userns=keep-id and --passwd-entry flags)
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
The wrapper uses --userns=keep-id and --passwd-entry which are
Podman-specific. Update prerequisites and Docker notes to match.
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
Add best-effort auto-detection for Go, Node.js, Python, Java, Rust, make,
and cmake. Each detected toolchain gets its binary and associated directories
mounted, plus relevant environment variables (GOROOT, GOPATH, JAVA_HOME).
Missing tools are silently skipped.
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
Address common objections: why not sandbox, why not permissions,
why Podman over Docker, and whether the container replaces permissions.
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
Rewrite sandbox FAQ to mention the real issue: shell expansion, pipes,
and compound commands triggering constant prompts. Add explicit FAQ entry
about outgoing network access not being restricted.
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
Name the specific risk (API key, GH token, SSH agent) and note that
it's acceptable for most users since these are already host-exposed.
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant