E2B.Volume reference
CreateVolume
Section titled “CreateVolume”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.
CreateVolume: Per-user volumes
Section titled “CreateVolume: Per-user volumes”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" }],});CreateVolumeHttp
Section titled “CreateVolumeHttp”Source:
packages/e2b/src/CreateVolumeHttp.tsKind: Layer · Provides:E2B.CreateVolume
HTTP implementation of CreateVolume. Works on any host.
CreateVolumeHttp: Provide the layer
Section titled “CreateVolumeHttp: Provide the layer”Effect.gen(function* () { const volumes = yield* E2B.CreateVolume(); // ...}).pipe(Effect.provide(E2B.CreateVolumeHttp))MountVolume
Section titled “MountVolume”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.
MountVolume: In a template program
Section titled “MountVolume: In a template program”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)),) {}MountVolume: From a Worker
Section titled “MountVolume: From a Worker”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" }],});MountVolumeLive
Section titled “MountVolumeLive”Source:
packages/e2b/src/MountVolumeLive.tsKind: 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.
MountVolumeLive: Provide the layer
Section titled “MountVolumeLive: Provide the layer”Effect.gen(function* () { const data = yield* E2B.MountVolume(Data, { path: "/data" }); // ...}).pipe(Effect.provide(E2B.MountVolumeLive))ReadVolume
Section titled “ReadVolume”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.
ReadVolume: Using the client
Section titled “ReadVolume: Using the client”const reports = yield* E2B.ReadVolume(Reports);// in fetch:const report = yield* reports.readText("/report.json");ReadVolumeHttp
Section titled “ReadVolumeHttp”Source:
packages/e2b/src/ReadVolumeHttp.tsKind: Layer · Provides:E2B.ReadVolume
HTTP implementation of ReadVolume. Works on any host.
ReadVolumeHttp: Provide the layer
Section titled “ReadVolumeHttp: Provide the layer”Effect.gen(function* () { const reports = yield* E2B.ReadVolume(Reports); // ...}).pipe(Effect.provide(E2B.ReadVolumeHttp))ReadWriteVolume
Section titled “ReadWriteVolume”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.
ReadWriteVolume: Using the client
Section titled “ReadWriteVolume: Using the client”const cache = yield* E2B.ReadWriteVolume(Cache);// in fetch:yield* cache.write("/notes.md", "hello");const notes = yield* cache.readText("/notes.md");ReadWriteVolumeHttp
Section titled “ReadWriteVolumeHttp”Source:
packages/e2b/src/ReadWriteVolumeHttp.tsKind: Layer · Provides:E2B.ReadWriteVolume
HTTP implementation of ReadWriteVolume. Works on any host.
ReadWriteVolumeHttp: Provide the layer
Section titled “ReadWriteVolumeHttp: Provide the layer”Effect.gen(function* () { const cache = yield* E2B.ReadWriteVolume(Cache); // ...}).pipe(Effect.provide(E2B.ReadWriteVolumeHttp))Volume
Section titled “Volume”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.
Volume: Creating a Volume
Section titled “Volume: Creating a Volume”A shared cache volume
export const Cache = E2B.Volume("Cache", {});A volume with a fixed name
export const Datasets = E2B.Volume("Datasets", { name: "datasets" });Volume: Mounting a Volume
Section titled “Volume: Mounting a Volume”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);WriteVolume
Section titled “WriteVolume”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.
WriteVolume: Using the client
Section titled “WriteVolume: Using the client”const inputs = yield* E2B.WriteVolume(Inputs);// in fetch:yield* inputs.write("/task.json", JSON.stringify(task));WriteVolumeHttp
Section titled “WriteVolumeHttp”Source:
packages/e2b/src/WriteVolumeHttp.tsKind: Layer · Provides:E2B.WriteVolume
HTTP implementation of WriteVolume. Works on any host.
WriteVolumeHttp: Provide the layer
Section titled “WriteVolumeHttp: Provide the layer”Effect.gen(function* () { const inputs = yield* E2B.WriteVolume(Inputs); // ...}).pipe(Effect.provide(E2B.WriteVolumeHttp))