Skip to content

E2B.Volume reference

Source: packages/e2b/src/CreateVolume.ts

Create and manage E2B volumes at runtime, by name: a home directory per user, a workspace per session. Mount one into a sandbox by its name, and read or write its files with files without a sandbox.

E2B volumes carry no metadata, so the volumes a host creates at runtime are not deleted when the host is destroyed. Delete them with delete when their owner goes away.

const volumes = yield* E2B.CreateVolume();
const sandboxes = yield* E2B.CreateSandbox(Agent);
// in fetch:
const home = yield* volumes.getOrCreate(`user-${user}`);
const sandbox = yield* sandboxes.create({
mounts: [{ volume: home, path: "/home/user/work" }],
});

Source: packages/e2b/src/CreateVolumeHttp.ts Kind: Layer · Provides: E2B.CreateVolume

HTTP implementation of CreateVolume. Works on any host.

Effect.gen(function* () {
const volumes = yield* E2B.CreateVolume();
// ...
}).pipe(Effect.provide(E2B.CreateVolumeHttp))

Source: packages/e2b/src/MountVolume.ts

Mount a declared E2B.Volume at a path.

In an E2B.Template program, the mount becomes part of the template: every sandbox created from it (with CreateSandbox(template) or E2B.Sandbox({ template })) mounts the volume, and the program finds its files at path. E2B attaches volumes when a sandbox is created, so a sandbox already running keeps the mounts it started with.

Anywhere else (a Worker, a Function), it returns a reference to pass to create({ mounts }).

E2B enables volumes per team; on a team without them, deploying the volume fails with VolumesNotEnabled.

export default class Api extends E2B.Template<Api>()(
"Api",
{ main: import.meta.url },
Effect.gen(function* () {
const data = yield* E2B.MountVolume(Data, { path: "/data" });
const fs = yield* FileSystem.FileSystem;
return {
fetch: Effect.gen(function* () {
const files = yield* fs.readDirectory(data.path);
return yield* HttpServerResponse.json(files);
}).pipe(Effect.orDie),
};
}).pipe(Effect.provide(E2B.MountVolumeLive)),
) {}
const data = yield* E2B.MountVolume(Data, { path: "/data" });
const sandboxes = yield* E2B.CreateSandbox(Agent);
const volumes = yield* E2B.CreateVolume();
// in fetch:
const home = yield* volumes.getOrCreate(`home-${user}`);
const sandbox = yield* sandboxes.create({
mounts: [data, { volume: home, path: "/home/user/work" }],
});

Source: packages/e2b/src/MountVolumeLive.ts Kind: Layer · Provides: E2B.MountVolume

The implementation of MountVolume. It makes no API call: E2B mounts a volume by name when a sandbox is created, so the binding binds the name onto the host and, in an E2B.Template program, adds the mount to the template.

Effect.gen(function* () {
const data = yield* E2B.MountVolume(Data, { path: "/data" });
// ...
}).pipe(Effect.provide(E2B.MountVolumeLive))

Source: packages/e2b/src/ReadVolume.ts

Read a Volume’s files from outside any sandbox: a report a sandbox wrote, a dataset to inspect.

The client talks to E2B’s volume content API with the volume’s own token, looked up once through the host’s API key.

const reports = yield* E2B.ReadVolume(Reports);
// in fetch:
const report = yield* reports.readText("/report.json");

Source: packages/e2b/src/ReadVolumeHttp.ts Kind: Layer · Provides: E2B.ReadVolume

HTTP implementation of ReadVolume. Works on any host.

Effect.gen(function* () {
const reports = yield* E2B.ReadVolume(Reports);
// ...
}).pipe(Effect.provide(E2B.ReadVolumeHttp))

Source: packages/e2b/src/ReadWriteVolume.ts

Read and write a Volume’s files from outside any sandbox.

The client talks to E2B’s volume content API with the volume’s own token, looked up once through the host’s API key.

const cache = yield* E2B.ReadWriteVolume(Cache);
// in fetch:
yield* cache.write("/notes.md", "hello");
const notes = yield* cache.readText("/notes.md");

Source: packages/e2b/src/ReadWriteVolumeHttp.ts Kind: Layer · Provides: E2B.ReadWriteVolume

HTTP implementation of ReadWriteVolume. Works on any host.

Effect.gen(function* () {
const cache = yield* E2B.ReadWriteVolume(Cache);
// ...
}).pipe(Effect.provide(E2B.ReadWriteVolumeHttp))

Source: packages/e2b/src/Volume.ts

A persistent E2B volume: a team-wide filesystem that sandboxes mount at a path and that outlives every sandbox using it.

Declare a volume when every sandbox shares it (a package cache, a dataset). Per-user and per-session volumes are created at runtime by name with E2B.CreateVolume(), and both kinds mount the same way.

E2B volumes carry no labels, so Alchemy recognises its volumes by their generated name. A volume found under an explicit name without prior state is reported as unowned and is only adopted with --adopt.

E2B enables volumes per team; on a team without them, a deploy fails with VolumesNotEnabled.

A shared cache volume

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

A volume with a fixed name

export const Datasets = E2B.Volume("Datasets", { name: "datasets" });

Mount it into a declared sandbox

export const Builder = E2B.Sandbox("Builder", {
template: Agent,
mounts: [{ volume: Cache, path: "/cache" }],
});

Mount it into the sandboxes a Worker creates

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

Volume: Reading files from outside a sandbox

Section titled “Volume: Reading files from outside a sandbox”
const reports = yield* E2B.ReadVolume(Reports);
const report = yield* reports.readFile("/report.json");

Volume: Referencing a volume the stack doesn’t manage

Section titled “Volume: Referencing a volume the stack doesn’t manage”

E2B.Volume.lookup finds an existing volume by name. Nothing is created, adopted or deleted.

const datasets = E2B.Volume.lookup({ name: "datasets" });
const files = yield* E2B.ReadVolume(datasets);

Source: packages/e2b/src/WriteVolume.ts

Write a Volume’s files from outside any sandbox: seed inputs before sandboxes start, or clean up after them.

The client talks to E2B’s volume content API with the volume’s own token, looked up once through the host’s API key.

const inputs = yield* E2B.WriteVolume(Inputs);
// in fetch:
yield* inputs.write("/task.json", JSON.stringify(task));

Source: packages/e2b/src/WriteVolumeHttp.ts Kind: Layer · Provides: E2B.WriteVolume

HTTP implementation of WriteVolume. Works on any host.

Effect.gen(function* () {
const inputs = yield* E2B.WriteVolume(Inputs);
// ...
}).pipe(Effect.provide(E2B.WriteVolumeHttp))