Skip to content

Daytona.Volume reference

Source: packages/daytona/src/CreateVolume.ts

Create, find and delete Daytona volumes at runtime: a volume per user, per project or per session, mounted into the sandboxes you create.

The host gets its own Daytona API key with read:volumes, write:volumes and delete:volumes. Volumes have only a name, so the prefix you give is how you find the ones it created. They are not deleted when the stack is destroyed: list() and delete the names with your prefix to clean them up.

const volumes = yield* Daytona.CreateVolume({ prefix: "user-" });
const sandboxes = yield* Daytona.CreateSandbox(Base);
return {
fetch: Effect.gen(function* () {
const home = yield* volumes.getOrCreate({ name: `user-${user}` });
const sandbox = yield* sandboxes.create({
mounts: [{ volume: home, path: "/home/daytona/work" }],
});
const ls = yield* sandbox.exec("ls /home/daytona/work");
return yield* HttpServerResponse.json(ls);
}),
};

Source: packages/daytona/src/MountVolume.ts

Mount a Volume at a path.

Inside a sandbox’s program, the volume is mounted into that sandbox: it joins the sandbox’s mounts. A mount change replaces the sandbox, since Daytona only mounts volumes when it creates one. Inside any other host (a Worker, a Lambda), the binding resolves the volume and returns a mount reference to pass to CreateSandbox’s create({ mounts }).

The reference has the same fields as a mounts entry: volume, path and subpath. Daytona has no per-volume access control, so the binding mints no credentials.

MountVolume: Mounting a Volume in a Program

Section titled “MountVolume: Mounting a Volume in a Program”
export default class Agent extends Daytona.Sandbox<Agent>()(
"Agent",
{ main: import.meta.url, public: true },
Effect.gen(function* () {
const data = yield* Daytona.MountVolume(Data, { path: "/data" });
const fs = yield* FileSystem.FileSystem;
return {
fetch: Effect.gen(function* () {
return yield* HttpServerResponse.json(yield* fs.readDirectory(data.path));
}),
};
}).pipe(Effect.provide(Daytona.MountVolumeLive)),
) {}

MountVolume: Mounting a Volume in Sandboxes You Create

Section titled “MountVolume: Mounting a Volume in Sandboxes You Create”
const cache = yield* Daytona.MountVolume(Cache, { path: "/cache" });
const sandboxes = yield* Daytona.CreateSandbox(Base);
const volumes = yield* Daytona.CreateVolume({ prefix: "user-" });
return {
fetch: Effect.gen(function* () {
const home = yield* volumes.getOrCreate({ name: `user-${user}` });
const sandbox = yield* sandboxes.create({
mounts: [cache, { volume: home, path: "/home/daytona/work" }],
});
return yield* HttpServerResponse.json(yield* sandbox.exec("ls /cache"));
}),
};

Source: packages/daytona/src/Volume.ts

A Daytona volume: a persistent disk, backed by object storage, that sandboxes mount at a path. Its files outlive every sandbox that mounts it, and several sandboxes can mount it at once.

Declare a volume here for data your whole app shares, like a dataset or a package cache. For a volume per user or per session, create it at runtime with CreateVolume.

export const Cache = Daytona.Volume("Cache", {});

Mount it in a sandbox declared at deploy

export const DevBox = Daytona.Sandbox("DevBox", {
snapshot: Base,
mounts: [{ volume: Cache, path: "/cache" }],
});

Mount it in sandboxes created at runtime

const cache = yield* Daytona.MountVolume(Cache, { path: "/cache" });
const sandbox = yield* sandboxes.create({ mounts: [cache] });

Volume.lookup references a volume Alchemy doesn’t manage (created in the Daytona dashboard or by another stack). It is read during plan/deploy, never created, updated or deleted.

const data = Daytona.Volume.lookup({ name: "datasets" });