Use this file to discover all available pages before exploring further.
Volumes are currently in private beta.
If you’d like access, please reach out to us at support@e2b.dev.
Volumes provide persistent storage that exists independently of sandbox lifecycles. Data written to a volume persists even after a sandbox is shut down, and the same volume can be mounted to multiple sandboxes — either at the same time for shared state across parallel agents, or sequentially to resume work in a new sandbox. You can also read and write to a volume directly through the SDK without mounting it to any sandbox.One volume shared across multiple sandboxesEach sandbox with its own volumeStandalone usage via SDKWhen a volume is mounted to a sandbox, files can be read and written directly at the mount path using the regular sandbox filesystem API. The Volume SDK methods covered below are meant for working with a volume when it is not mounted to any sandbox.
Pass volumeMounts / volume_mounts to Sandbox.create() to attach one or more volumes when the sandbox starts. Keys are the mount paths inside the sandbox; values are either a Volume object or the volume name.
import { Volume, Sandbox } from 'e2b'const volume = await Volume.create('my-volume')// You can pass a Volume objectconst sandbox = await Sandbox.create({ volumeMounts: { '/mnt/my-data': volume, },})// Or pass the volume name directlyconst sandbox = await Sandbox.create({ volumeMounts: { '/mnt/my-data': 'my-volume', },})// Files written to /mnt/my-data inside the sandbox are persisted in the volumeawait sandbox.files.write('/mnt/my-data/hello.txt', 'Hello, world!')
Inspect files and directories with getInfo() / get_info(), check for existence with exists(), or change ownership and permissions with updateMetadata() / update_metadata().
Iterate over the files in the directory and upload each one. The SDK does not currently provide a recursive upload helper, so nested directories need to be walked explicitly.
import fs from 'fs'import path from 'path'import { Volume } from 'e2b'const volume = await Volume.create('my-volume')const directoryPath = '/local/dir'const files = fs.readdirSync(directoryPath)for (const file of files) { const fullPath = path.join(directoryPath, file) // Skip directories if (!fs.statSync(fullPath).isFile()) continue const content = fs.readFileSync(fullPath) await volume.writeFile(`/upload/${file}`, content)}