Skip to content

Part 1: Build a Warm Snapshot

Build an API that gives agents sandboxes. The slow setup runs once, when you deploy: an image pulled into a snapshot, and a second snapshot of it with a repository cloned. While the app runs, every sandbox starts from that snapshot, already set up.

The finished code is in examples/daytona-sandboxes.

Finish Daytona setup and Cloudflare setup.

A snapshot is the image a sandbox boots from, with its size:

src/Images.ts
import * as Daytona from "@alchemy.run/daytona";
export const Base = Daytona.Snapshot("Base", {
image: "node:22-bookworm",
cpu: 1,
memory: 1,
disk: 3,
});

Daytona pulls node:22-bookworm once, with Node.js and git.

Capture a warm snapshot with the repository cloned

Section titled “Capture a warm snapshot with the repository cloned”
src/Images.ts
export const Warm = Daytona.Snapshot("Warm", {
from: Base,
run: ["git clone --depth 1 https://github.com/sindresorhus/is /home/daytona/repo"],
});

At deploy, Alchemy starts a sandbox from Base, runs the commands, captures its disk as Warm, and deletes the sandbox. Every sandbox the app starts boots from it, with the repository already in /home/daytona/repo.

alchemy.run.ts
import * as Cloudflare from "@alchemy.run/cloudflare";
import * as Daytona from "@alchemy.run/daytona";
import * as Alchemy from "alchemy";
import * as Effect from "effect/Effect";
import * as Layer from "effect/Layer";
import { Warm } from "./src/Images.ts";
export default Alchemy.Stack(
"DaytonaSandboxes",
{
providers: Layer.mergeAll(Cloudflare.providers(), Daytona.providers()),
state: Alchemy.localState(),
},
Effect.gen(function* () {
const warm = yield* Warm;
return { snapshot: warm.name };
}),
);

Warm starts from Base, so deploying it builds both.

Terminal window
pnpm alchemy deploy

Both snapshots show up under Snapshots in the Daytona dashboard once they’re active. A deploy that changes neither leaves them alone.

Part 2 starts sandboxes from it while the app runs.