Skip to main content

Documentation Index

Fetch the complete documentation index at: https://e2b-squash-sandbox-pages.mintlify.app/llms.txt

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.
Most use cases don’t need volumes. Every sandbox already has its own persistent filesystem — when you pause and resume a sandbox, all files are preserved automatically. Volumes are for when you need storage that is shared across multiple sandboxes or persists independently of any single sandbox.
Volumes provide storage that exists independently of any single sandbox. Data written to a volume survives sandbox shutdowns and can be mounted to different sandboxes over time. One volume shared across multiple sandboxes Each sandbox with its own volume Standalone usage via SDK When a volume is mounted to a sandbox, files can be read and written directly at the mount path. The SDK methods below are meant to be used when the volume is not mounted to any sandbox.

Managing volumes

Create a volume

Volume names can only contain letters, numbers, and hyphens.
import { Volume } from 'e2b'

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

Connect to an existing volume

You can connect to an existing volume by its ID using the connect() method.
import { Volume } from 'e2b'

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

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

Mounting volumes

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')

// You can pass a Volume object
const sandbox = await Sandbox.create({
  volumeMounts: {
    '/mnt/my-data': volume,
  },
})

// Or pass the volume name directly
const sandbox = await Sandbox.create({
  volumeMounts: {
    '/mnt/my-data': 'my-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!')

Read and write files

Reading files

You can read files from a volume using the readFile() / read_file() method.
import { Volume } from 'e2b'

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

const content = await volume.readFile('/path/to/file')
console.log(content)

Writing files

You can write files to a volume using the writeFile() / write_file() method.
import { Volume } from 'e2b'

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

await volume.writeFile('/path/to/file', 'file content')

Creating directories

You can create directories in a volume using the makeDir() / make_dir() method.
import { Volume } from 'e2b'

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

await volume.makeDir('/path/to/dir')

// Create nested directories with force option
await volume.makeDir('/path/to/nested/dir', { force: true })

Listing directory contents

You can list the contents of a directory in a volume using the list() method.
import { Volume } from 'e2b'

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

const entries = await volume.list('/path/to/dir')
console.log(entries)
// [
//   { name: 'file.txt', type: 'file', path: '/path/to/dir/file.txt', size: 13, ... },
//   { name: 'subdir', type: 'directory', path: '/path/to/dir/subdir', size: 0, ... },
// ]

Removing files or directories

You can remove files or directories from a volume using the remove() method.
import { Volume } from 'e2b'

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

// Remove a file
await volume.remove('/path/to/file')

// Remove a directory recursively
await volume.remove('/path/to/dir', { recursive: true })

File and directory metadata

You can get information about a file or directory in a volume using the getInfo() / get_info() method.

File metadata

import { Volume } from 'e2b'

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

// Create a new file
await volume.writeFile('/test_file.txt', 'Hello, world!')

// Get information about the file
const info = await volume.getInfo('/test_file.txt')

console.log(info)
// {
//   name: 'test_file.txt',
//   type: 'file',
//   path: '/test_file.txt',
//   size: 13,
//   mode: 0o644,
//   uid: 0,
//   gid: 0,
//   atime: 2025-05-26T12:00:00.000Z,
//   mtime: 2025-05-26T12:00:00.000Z,
//   ctime: 2025-05-26T12:00:00.000Z,
// }

Directory metadata

import { Volume } from 'e2b'

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

// Create a new directory
await volume.makeDir('/test_dir')

// Get information about the directory
const info = await volume.getInfo('/test_dir')

console.log(info)
// {
//   name: 'test_dir',
//   type: 'directory',
//   path: '/test_dir',
//   size: 0,
//   mode: 0o755,
//   uid: 0,
//   gid: 0,
//   atime: 2025-05-26T12:00:00.000Z,
//   mtime: 2025-05-26T12:00:00.000Z,
//   ctime: 2025-05-26T12:00:00.000Z,
// }

Checking if a path exists

You can check whether a file or directory exists in a volume using the exists() method.
import { Volume } from 'e2b'

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

const fileExists = await volume.exists('/test_file.txt')
console.log(fileExists) // true or false

Updating metadata

You can update file or directory metadata such as user ID, group ID, and permissions mode using the updateMetadata() / update_metadata() method.
import { Volume } from 'e2b'

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

await volume.writeFile('/test_file.txt', 'Hello, world!')

const updated = await volume.updateMetadata('/test_file.txt', { uid: 1000, gid: 1000, mode: 0o600 })

console.log(updated)
// {
//   name: 'test_file.txt',
//   type: 'file',
//   path: '/test_file.txt',
//   size: 13,
//   mode: 0o600,
//   uid: 1000,
//   gid: 1000,
//   ...
// }

Upload data

You can upload data to a volume using the writeFile() / write_file() method.

Upload single file

import fs from 'fs'
import { Volume } from 'e2b'

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

// Read file from local filesystem
const content = fs.readFileSync('/local/path')
// Upload file to volume
await volume.writeFile('/path/in/volume', content)

Upload directory / multiple files

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)
}

Download data

You can download data from a volume using the readFile() / read_file() method.
import fs from 'fs'
import { Volume } from 'e2b'

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

// Read file from volume
const content = await volume.readFile('/path/in/volume')
// Write file to local filesystem
fs.writeFileSync('/local/path', content)