Part 1: Set Up a Sandbox
Build an API that gives agents sandboxes. The slow setup runs once, when you deploy: a sandbox with a repository cloned onto its disk. While the app runs, every sandbox is a fork of it, already set up.
The finished code is in examples/archil-sandbox.
Prerequisites
Section titled “Prerequisites”Create a project
Section titled “Create a project”mkdir my-app && cd my-app && pnpm initmkdir my-app && cd my-app && bun init -ymkdir my-app && cd my-app && npm init -ymkdir my-app && cd my-app && yarn init -ypnpm add https://pkg.alchemy.run/alchemy/pr:3743:41147c9 https://pkg.alchemy.run/@alchemy.run/archil/pr:3743:41147c9 effect @effect/platform-nodebun add https://pkg.alchemy.run/alchemy/pr:3743:41147c9 https://pkg.alchemy.run/@alchemy.run/archil/pr:3743:41147c9 effect @effect/platform-nodenpm install https://pkg.alchemy.run/alchemy/pr:3743:41147c9 https://pkg.alchemy.run/@alchemy.run/archil/pr:3743:41147c9 effect @effect/platform-nodeyarn add https://pkg.alchemy.run/alchemy/pr:3743:41147c9 https://pkg.alchemy.run/@alchemy.run/archil/pr:3743:41147c9 effect @effect/platform-nodeDeclare the sandbox
Section titled “Declare the sandbox”import * as Archil from "@alchemy.run/archil";
export const Golden = Archil.Sandbox("Golden", { run: ["git clone --depth 1 https://github.com/sindresorhus/is /work/is"],});A sandbox is a Firecracker microVM whose root filesystem is a disk of its own. At deploy, Alchemy creates Golden and runs the run commands in it, in order. A command that exits non-zero fails the deploy.
Create the Stack
Section titled “Create the Stack”import * as Archil from "@alchemy.run/archil";import * as Alchemy from "alchemy";import * as Effect from "effect/Effect";import { Golden } from "./src/Golden.ts";
export default Alchemy.Stack( "ArchilSandboxExample", { providers: Archil.providers(), state: Alchemy.localState() }, Effect.gen(function* () { const golden = yield* Golden; return { sandbox: golden.name }; }),);Archil.providers() reads your key from your Alchemy profile.
Deploy
Section titled “Deploy”pnpm alchemy deploybun alchemy deploynpx alchemy deployyarn alchemy deployGolden shows up under Sandboxes in the Archil console, with the repository in /work/is. A deploy that leaves the commands unchanged leaves it alone. When it’s idle, it pauses.
Part 2 forks it while the app runs.