Sandcastle

A TypeScript library for orchestrating AI coding agents, tools such as Claude Code or Codex that read and change your code on their own. Each agent runs in an isolated sandbox: a container, a VM or an OS process sandbox that limits what the agent can reach, so you can leave it to work.
- GitHub stars
- 9,081
- npm downloads a week
- 215,504
npm install --save-dev @ai-hero/sandcastleimport { run, claudeCode } from "@ai-hero/sandcastle";import { bwrap } from "@ai-hero/sandcastle/sandboxes/bwrap";await run({agent: claudeCode("claude-opus-4-8"),sandbox: bwrap(), // seatbelt() on macOS, or docker(), podman(), vercel(), or your own providerpromptFile: ".sandcastle/prompt.md",});
How it works
You invoke agents with a single
sandcastle.run().Sandcastle handles sandboxing the agent with a configurable [branch strategy](/sandcastle/glossary#branch-strategy), which decides where the agent's commits go: onto your current branch, onto a temporary branch it merges back for you, or onto a branch you name.
The commits made on the branches get merged back.
Sandbox providers
- Bubblewrap
@ai-hero/Native (bind-mount)sandcastle/ sandboxes/ bwrap - Seatbelt
@ai-hero/Native (bind-mount)sandcastle/ sandboxes/ seatbelt - Docker
@ai-hero/Bind-mountsandcastle/ sandboxes/ docker - Podman
@ai-hero/Bind-mountsandcastle/ sandboxes/ podman - E2B
@ai-hero/Isolatedsandcastle/ sandboxes/ e2b - Modal
@ai-hero/Isolatedsandcastle/ sandboxes/ modal - Sprites
@ai-hero/Isolatedsandcastle/ sandboxes/ sprites - Vercel
@ai-hero/Isolatedsandcastle/ sandboxes/ vercel - No-sandbox
@ai-hero/Nonesandcastle/ sandboxes/ no-sandbox - Custom providersBind-mount when the sandbox can mount a host directory. Isolated when it has its own filesystem.
Documentation
Concepts
- Core conceptsSandcastle runs on the host, creates a sandbox, and invokes an agent inside it.
- Sandbox providersThe sandbox option on run(), interactive(), and createSandbox() accepts any sandbox provider, including noSandbox(): opt in to running the agent directly…
- Branch strategiesPass branchStrategy to run().
- Agent providersSandcastle ships agent providers for Claude Code, Codex, Pi, Copilot, Cursor and OpenCode: claudeCode(), codex(), pi(), copilot(), cursor() and…
- Agent sessionsSandcastle captures the agent session, the agent's own record of the conversation, after each iteration.
Running
- PromptsA prompt template is a prompt that Sandcastle reads from a file and fills in before the agent sees it.
- IterationsmaxIterations sets how many iterations run() may run (default 1).
- Structured outputStructured output is a typed answer from the agent: it prints JSON inside an XML tag you choose, and Sandcastle parses it, checks it, and returns it on…
- HooksPass hooks to run().
- Run logsPass logging to run().
- InitRun init once in a new repo.
Reference
- run() and createSandbox()Sandcastle exports a programmatic run() function for use in scripts, CI pipelines, or custom tooling.
- CLI commandsScaffolds the .sandcastle/ config directory and, for an image-based provider, builds the container image.
- GlossaryThe words these docs use, one entry each, in alphabetical order.