Skip to content

feat(glyph): sandboxed agent container infrastructure#403

Draft
stackptr wants to merge 1 commit intomainfrom
feat/glyph-agent-sandbox
Draft

feat(glyph): sandboxed agent container infrastructure#403
stackptr wants to merge 1 commit intomainfrom
feat/glyph-agent-sandbox

Conversation

@stackptr
Copy link
Copy Markdown
Owner

@stackptr stackptr commented Mar 24, 2026

Summary

  • Add services.agent-sandbox NixOS module for running Claude Code in disposable systemd-nspawn containers
  • Each run gets: isolated overlay filesystem, bind-mounted workspace, network access for API/MCP calls
  • Sandbox is destroyed after completion (or preserved with --keep)
  • CLI tool agent-sandbox for launching runs

Architecture

agent-sandbox <repo> <prompt>
  β†’ clone/copy repo to workspace
  β†’ overlay mount: read-only rootfs + writable upper layer
  β†’ systemd-nspawn container with:
      - claude-code, git, node, ripgrep, etc.
      - /workspace bind-mounted (writable)
      - /nix/store bind-mounted (read-only)
      - ANTHROPIC_API_KEY injected from agenix secret
      - --dangerously-skip-permissions (sandbox IS the boundary)
  β†’ agent runs, modifies workspace
  β†’ diff shown on completion
  β†’ sandbox cleaned up

Usage

# Run agent on a remote repo
sudo agent-sandbox https://github.com/org/repo "Fix the failing tests"

# Run agent on a local path, keep sandbox after
sudo agent-sandbox --keep /home/mu/project "Refactor the auth module"

# Specify branch and session name
sudo agent-sandbox -b feat/new-api -n my-session https://github.com/org/repo "Add pagination"

Setup required

  • Create hosts/glyph/secrets/agent-sandbox-api-key.age with ANTHROPIC_API_KEY value
  • Add to lib/secrets/glyph.nix

Test plan

  • Create agenix secret for API key
  • Deploy to glyph
  • Run sudo agent-sandbox https://github.com/stackptr/rc "List all NixOS hosts configured in this repo"
  • Verify container isolation (no access to host filesystem outside /workspace)
  • Verify cleanup after completion
  • Test --keep flag preserves workspace

πŸ€– Generated with Claude Code

NixOS module for running AI coding agents (Claude Code) in disposable
systemd-nspawn containers. Each run gets an isolated filesystem with
overlay on a minimal rootfs, bind-mounted workspace, and network access
for API calls.

Usage: agent-sandbox <repo-url-or-path> <prompt>

Requires creating agent-sandbox-api-key.age secret with the Anthropic
API key, encrypted for glyph.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Owner Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@stackptr stackptr changed the title feat(glyph): add sandboxed agent container infrastructure feat(glyph): sandboxed agent container infrastructure Mar 24, 2026
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