Sandcastle
A TypeScript library for orchestrating AI coding agents in isolated sandboxes using Docker, Podman, or Vercel, with configurable branch strategies and a simple sandcastle.run() API.
At a Glance
About Sandcastle
Sandcastle is a TypeScript library that lets you orchestrate AI coding agents inside isolated sandboxes with a single sandcastle.run() call. It handles sandboxing via configurable providers (Docker, Podman, Vercel, or custom), manages git branch strategies so agent commits land cleanly, and merges changes back automatically. It is provider-agnostic and designed for parallelizing multiple AFK agents, building review pipelines, or composing custom agent workflows.
sandcastle.run()— invoke an agent with a single call; Sandcastle handles sandbox lifecycle, branching, and commit merging automatically.- Multiple sandbox providers — built-in support for Docker, Podman, and Vercel Firecracker microVMs; create custom bind-mount or isolated providers using
createBindMountSandboxProvider/createIsolatedSandboxProvider. - Branch strategies — choose
head(direct write),merge-to-head(temp branch merged back), orbranch(explicit named branch) to control where agent commits land. createSandbox()— reuse a single sandbox across multiple agent runs to avoid repeated container startup costs and keep all runs on the same branch.createWorktree()— manage git worktrees as independent first-class objects, enabling interactive-then-AFK agent handoffs on the same branch.- Prompt system — use inline strings or prompt files with
{{KEY}}placeholder substitution, dynamic shell expression expansion (!`command`), and built-in{{SOURCE_BRANCH}}/{{TARGET_BRANCH}}variables. - Lifecycle hooks — run setup commands on the host or inside the sandbox at
onWorktreeReadyandonSandboxReadyhook points, with per-hook timeout control. - Session capture & resume — automatically captures Claude Code session JSONL to the host for
claude --resumesupport; passresumeSessionto continue a prior conversation in a new sandbox. - CLI tooling —
sandcastle initscaffolds the.sandcastle/config directory and Docker image;sandcastle docker build-image/sandcastle podman build-imagerebuild images after Dockerfile changes. - Workflow templates — choose from
blank,simple-loop,sequential-reviewer,parallel-planner, orparallel-planner-with-reviewduringsandcastle initto scaffold ready-to-use orchestration scripts. - Iteration control — configure
maxIterations,completionSignal, andidleTimeoutSecondsto control how long agents run and when they stop. - AbortSignal support — pass a
signaltorun()to cancel in-flight agent subprocesses and lifecycle hooks cleanly.
Community Discussions
Be the first to start a conversation about Sandcastle
Share your experience with Sandcastle, ask questions, or help others learn from your insights.
Pricing
Open Source (MIT)
Fully free and open-source under the MIT License. Use, modify, and distribute freely.
- Full sandcastle.run() API
- Docker, Podman, and Vercel sandbox providers
- Custom sandbox provider support
- All branch strategies (head, merge-to-head, branch)
- CLI tooling (sandcastle init, build-image)
Capabilities
Key Features
- Provider-agnostic sandbox orchestration (Docker, Podman, Vercel, custom)
- Single sandcastle.run() API for invoking AI coding agents
- Configurable branch strategies: head, merge-to-head, branch
- createSandbox() for reusable multi-run sandboxes
- createWorktree() for independent git worktree lifecycle management
- Prompt files with {{KEY}} substitution and !`command` shell expansion
- Built-in {{SOURCE_BRANCH}} and {{TARGET_BRANCH}} prompt variables
- Lifecycle hooks (host and sandbox) at onWorktreeReady and onSandboxReady
- Session capture and resume for Claude Code agents
- CLI: sandcastle init, docker build-image, podman build-image
- Workflow templates: blank, simple-loop, sequential-reviewer, parallel-planner, parallel-planner-with-review
- maxIterations, completionSignal, and idleTimeoutSeconds controls
- AbortSignal support for cancellation
- Custom sandbox provider API (bind-mount and isolated)
- Parallel agent execution support
- Per-hook timeout configuration
- Environment variable injection via agent and sandbox provider env options
- Automatic worktree cleanup with await using / Symbol.asyncDispose
