Skip to main content
Volumes provide persistent storage that exists independently of sandbox lifecycles. Data written to a volume persists even after a sandbox is shut down, and volumes can be mounted to multiple sandboxes over time. With E2B SDK you can:

Create a volume

import { Volume } from 'e2b'

const volume = await Volume.create('my-volume')
console.log(volume.volumeId) // Volume ID
console.log(volume.name)     // 'my-volume'

Mount a volume to a sandbox

You can mount one or more volumes to a sandbox when creating it. The keys of the volumeMounts / volume_mounts object are the mount paths inside the sandbox.
import { Volume, Sandbox } from 'e2b'

const volume = await Volume.create('my-volume')

const sandbox = await Sandbox.create({
  volumeMounts: {
    '/mnt/my-data': volume,
  },
})

// Files written to /mnt/my-data inside the sandbox are persisted in the volume
await sandbox.files.write('/mnt/my-data/hello.txt', 'Hello, world!')

List volumes

import { Volume } from 'e2b'

const volumes = await Volume.list()
console.log(volumes)
// [{ volumeId: '...', name: 'my-volume' }, ...]

Get volume info

import { Volume } from 'e2b'

const info = await Volume.getInfo('volume-id')
console.log(info)
// { volumeId: '...', name: 'my-volume' }

Destroy a volume

import { Volume } from 'e2b'

const success = await Volume.destroy('volume-id')
console.log(success) // true