Skip to content

Daytona

Daytona runs sandboxes: isolated Linux machines for code you don’t fully trust, like an agent’s tool calls, a user’s code or a test run. Each sandbox boots from a snapshot, with its own filesystem, processes and network. Its toolbox API runs commands, edits files, drives git and terminals, and serves previews of its ports. An idle sandbox stops and keeps its disk, and a stopped one is archived and can later be deleted.

New to Daytona? Start with What is Daytona?.

A snapshot is the image your sandboxes boot from, with their size:

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

A Worker creates a sandbox from it per request, runs a command, and deletes it:

src/Api.ts
import * as Cloudflare from "@alchemy.run/cloudflare";
import * as Daytona from "@alchemy.run/daytona";
import * as Effect from "effect/Effect";
import * as HttpServerResponse from "effect/http/HttpServerResponse";
import { Base } from "./Images.ts";
export default class Api extends Cloudflare.Worker<Api>()(
"Api",
{ main: import.meta.url },
Effect.gen(function* () {
const sandboxes = yield* Daytona.CreateSandbox(Base);
return {
fetch: Effect.gen(function* () {
const sandbox = yield* Effect.acquireRelease(sandboxes.create(), (s) =>
sandboxes.delete(s.sandboxId).pipe(Effect.ignore),
);
const version = yield* sandbox.exec("node --version");
return yield* HttpServerResponse.json(version);
}).pipe(Effect.scoped, Effect.orDie),
};
}).pipe(Effect.provide(Daytona.CreateSandboxHttp)),
) {}

And the Stack deploys both, giving the Worker its own Daytona API key that can only create and delete sandboxes:

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 Api from "./src/Api.ts";
export default Alchemy.Stack(
"Sandboxes",
{ providers: Layer.mergeAll(Cloudflare.providers(), Daytona.providers()) },
Effect.gen(function* () {
const api = yield* Api;
return { url: api.url };
}),
);

Want to build? Start with Setup to connect your organization, then the tutorial goes from a snapshot to a sandbox per user, one step at a time.

Looking for something specific? Every section of these docs is listed below, and every resource is in the generated API reference.