Skip to main content

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)
from e2b import Volume

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

content = volume.read_file('/path/to/file')
print(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')
from e2b import Volume

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

volume.write_file('/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 })
from e2b import Volume

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

volume.make_dir('/path/to/dir')

# Create nested directories with force option
volume.make_dir('/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, ... },
// ]
from e2b import Volume

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

entries = volume.list('/path/to/dir')
print(entries)
# [
#   VolumeEntryStat(name='file.txt', type_='file', path='/path/to/dir/file.txt', size=13, ...),
#   VolumeEntryStat(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 })
from e2b import Volume

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

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

# Remove a directory recursively
volume.remove('/path/to/dir', recursive=True)