Skip to content

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.

Terminal window
mkdir my-app && cd my-app && pnpm init
Terminal window
pnpm add https://pkg.alchemy.run/alchemy/pr:3743:41147c9 https://pkg.alchemy.run/@alchemy.run/archil/pr:3743:41147c9 effect @effect/platform-node
src/Golden.ts
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.

alchemy.run.ts
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.

Terminal window
pnpm alchemy deploy

Golden 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.