Skip to content

Snapshots

A snapshot is the image a sandbox boots from, with the size every sandbox from it gets: CPU, memory, disk and GPUs. Daytona builds it once and every sandbox starts from a copy. Snapshots can’t be changed: changing what one is built from replaces it.

Daytona makes a snapshot from an image, from a Dockerfile, or from another snapshot with commands run in it. That last one is how you get a warm base: a snapshot with a repository already cloned and its dependencies installed, so sandboxes start ready to work.

sandbox from Basegit clonepnpm installcaptureWarmsnapshot Warmsandboxesready at bootready at bootdeploysandbox from Basegit clonepnpm installcaptureWarmsnapshot Warmsandboxesready at bootready at bootdeploy
Deploy starts a sandbox from Base, runs the commands, captures its disk as Warm and deletes the sandbox. Every sandbox created from Warm starts with the repository cloned and installed.
src/Images.ts
import * as Daytona from "@alchemy.run/daytona";
export const Node = Daytona.Snapshot("Node", {
image: "node:22-bookworm",
cpu: 2,
memory: 4,
disk: 10,
});

Use a fixed tag or digest. Daytona rejects latest, lts and stable, and deploy fails before calling it.

src/Images.ts
import * as Daytona from "@alchemy.run/daytona";
import * as Config from "effect/Config";
export const Ghcr = Daytona.Registry("Ghcr", {
url: "ghcr.io",
username: "alchemy-run",
password: Config.Redacted("GHCR_TOKEN"),
});
export const App = Daytona.Snapshot("App", {
image: "ghcr.io/alchemy-run/app:1.4.0",
registry: Ghcr,
});

Daytona picks the registry whose url matches the image’s host.

src/Images.ts
import * as Dockerfile from "@alchemy.run/docker/Dockerfile";
import * as Daytona from "@alchemy.run/daytona";
export const Tools = Daytona.Snapshot("Tools", {
dockerfile: Dockerfile.inline`
FROM node:22-bookworm
RUN apt-get update && apt-get install -y git ripgrep
`,
});

Daytona’s builders run the build; you don’t need Docker.

src/Images.ts
import * as Daytona from "@alchemy.run/daytona";
export const App = Daytona.Snapshot("App", {
context: "./sandbox",
build: { args: { NODE_ENV: "production" } },
});

The files ./sandbox/Dockerfile copies are uploaded to Daytona, minus anything in .dockerignore. Changing one of them rebuilds the snapshot. Build arguments are written into the Dockerfile’s ARG defaults. Daytona builds for linux/amd64 only. Daytona’s builders can’t receive build secrets, so setting build.secrets builds with your local Docker and pushes the image to Daytona instead.

src/Images.ts
import * as Daytona from "@alchemy.run/daytona";
export const Base = Daytona.Snapshot("Base", { image: "node:22-bookworm" });
export const Warm = Daytona.Snapshot("Warm", {
from: Base,
run: [
"git clone https://github.com/alchemy-run/alchemy /home/daytona/alchemy",
"cd /home/daytona/alchemy && corepack enable && pnpm install",
],
});

Deploy starts a sandbox from Base, runs the commands, captures its disk as Warm, and deletes the sandbox. Sandboxes created from Warm start with the repository cloned and installed.

export const Pool = Daytona.WarmPool("Pool", { snapshot: Warm, size: 4 });

Daytona keeps four started sandboxes of Warm ready and hands one out on each create. They are billed while they wait.

// construction
const images = yield* Daytona.CreateSnapshot({ prefix: "repo-" });
const warm = yield* Warm;
// per request
const name = `repo-${owner}-${repo}`;
const base =
(yield* images.get(name)) ??
(yield* images.create({
name,
from: warm.name,
run: [`git clone https://github.com/${owner}/${repo} /home/daytona/repo`],
}));

CreateSnapshot builds a base per repository the first time a user needs one. Snapshots have only a name, so prefix is how you find the ones it built; they are not deleted when the stack is destroyed.

yield* sandbox.createSandboxSnapshot({ name: `checkpoint-${task}` });

Daytona deactivates a snapshot nobody used for two weeks. Deploy reactivates it; at runtime, activate it before you create from it:

yield* images.activate(name);