Branches and checkpoints
A checkpoint is a named snapshot of a disk. It takes about 15 ms whatever the disk’s size, and never changes once taken. A branch is a writable copy of a disk started from a checkpoint, in about 35 ms. Writes on a branch never reach the disk or its other branches, so each agent, session or CI job can get a copy of its own.
Each branch shares the seed until it writes
Section titled “Each branch shares the seed until it writes”Seed a disk and checkpoint it
Section titled “Seed a disk and checkpoint it”Archil.Checkpoint runs commands against the disk at deploy time, then takes the checkpoint in the same microVM, so it holds exactly what they produced:
import * as Archil from "@alchemy.run/archil";import * as Effect from "effect/Effect";
export const Seed = Archil.Disk("Seed", {});
export const Base = Effect.gen(function* () { const seed = yield* Seed; return yield* Archil.Checkpoint("Base", { disk: seed.diskId, name: "base", run: ["git clone --depth 1 https://github.com/acme/app repo"], });});Branch a disk per session
Section titled “Branch a disk per session”Archil.BranchDisk gives a Worker or Lambda a client that creates branches while the app runs:
const seeds = yield* Archil.BranchDisk(Seed);const branch = yield* seeds.branch({ name: "session-42", fromCheckpoint: "base" });Mount it on your own host with MountDisk and branch: "session-42". Branches share the disk’s credentials, so a disk user that mounts the disk can mount any of its branches. A sandbox can’t mount a branch yet.
Declare a long-lived branch
Section titled “Declare a long-lived branch”A branch that lives as long as the Stack, like a staging copy, is a resource:
export const Staging = Effect.gen(function* () { const seed = yield* Seed; const base = yield* Base; return yield* Archil.Branch("Staging", { disk: seed.diskId, fromCheckpoint: base.name });});Fork a sandbox in milliseconds
Section titled “Fork a sandbox in milliseconds”A sandbox’s root filesystem is a disk too, so fork uses the same checkpoint and branch to copy a sandbox in milliseconds. A sandbox with mounted disks has to be stopped first.
const copy = yield* sandbox.fork({ name: "task-1-retry" });Branches go when the disk does
Section titled “Branches go when the disk does”Archil can’t delete checkpoints or branches yet. Destroying an Archil.Checkpoint or Archil.Branch removes it from Alchemy’s state only, and deleting the disk deletes them with it.