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.
- You invoke agents with a single
sandcastle.run(). - Sandcastle handles sandboxing the agent with a configurable 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.
Sandcastle is provider-agnostic. It ships with native sandboxes that use your OS's own process sandbox (Bubblewrap on Linux and WSL2, Seatbelt on macOS), image-based providers for Docker and Podman, and cloud providers for Daytona, E2B, Fly.io Sprites, Modal and Vercel, and you can create your own. Great for parallelizing multiple AFK agents, creating review pipelines, or even just orchestrating your own agents.
- Git
- A sandbox provider: the function, such as
bwrap()ordocker(), that creates the sandbox and runs the agent in it. You pass it torun()as thesandboxoption. Built-in options:- Native sandboxes (recommended for local development): no image to build and no daemon to run. The agent uses the tools already installed on your host, the machine you run Sandcastle on.
bwrap()on Linux, and on Windows inside WSL2: needs Bubblewrap (sudo apt install bubblewrap, or your distro's equivalent)seatbelt()on macOS 14 or later: nothing to install
- Docker Desktop or Podman: image-based, with a VM boundary on macOS and Windows
- Vercel: cloud-based Firecracker microVMs via
@vercel/sandbox - Or create your own using
createBindMountSandboxProviderorcreateIsolatedSandboxProvider
- Native sandboxes (recommended for local development): no image to build and no daemon to run. The agent uses the tools already installed on your host, the machine you run Sandcastle on.
- Install the package:
npm install --save-dev @ai-hero/sandcastle- Run
npx @ai-hero/sandcastle init. Init is the one-time setup command: it scaffolds a.sandcastledirectory with all the files needed, lists your OS's native sandbox first, marked "(recommended)", and checks that it works on your machine.
npx @ai-hero/sandcastle init- Copy
.sandcastle/.env.exampleto.sandcastle/.env, then fill in your default values forCLAUDE_CODE_OAUTH_TOKEN(runclaude setup-tokenon your host to get one). To use an Anthropic API key instead, uncomment and fill inANTHROPIC_API_KEY. A native sandbox hides your host's stored logins from the agent, so the agent logs in only through these env vars.
cp .sandcastle/.env.example .sandcastle/.env- Run the
.sandcastle/main.mtsfile withnpx tsx(init names itmain.tsinstead when yourpackage.jsonhas"type": "module")
npx tsx .sandcastle/main.mts// 4. Run the agent via the JS API
import { 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 provider
promptFile: ".sandcastle/prompt.md",
});