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.
Every sandbox starts from a copy
Section titled “Every sandbox starts from a copy”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.
Pull an image
Section titled “Pull an image”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.
Pull from a private registry
Section titled “Pull from a private registry”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.
Build a Dockerfile on Daytona
Section titled “Build a Dockerfile on Daytona”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.
Build a directory with its Dockerfile
Section titled “Build a directory with its Dockerfile”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.
Capture a warm base
Section titled “Capture a warm base”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.
Keep sandboxes warm
Section titled “Keep sandboxes warm”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.
Build snapshots at runtime
Section titled “Build snapshots at runtime”// constructionconst images = yield* Daytona.CreateSnapshot({ prefix: "repo-" });const warm = yield* Warm;// per requestconst 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.
Snapshot a running sandbox
Section titled “Snapshot a running sandbox”yield* sandbox.createSandboxSnapshot({ name: `checkpoint-${task}` });Unused snapshots are deactivated
Section titled “Unused snapshots are deactivated”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);