> ## Documentation Index
> Fetch the complete documentation index at: https://e2b.manicule.dev/llms.txt
> Use this file to discover all available pages before exploring further.
> For every page in one file, fetch https://e2b.manicule.dev/llms-full.txt (large).
> To search and read these docs as tools, connect the MCP server at https://e2b.manicule.dev/api/mcp.
> Every agent surface: https://e2b.manicule.dev/.well-known/llms-manifest.json

# Read & write files (/docs/volumes/read-write)

<!-- agent-signals: reading_time_min: 2 · est_tokens: 776 · updated: 2026-07-30 -->
Related: [Download data from volume](/docs/volumes/download.md), [Get information about a file or directory](/docs/volumes/info.md), [Managing volumes](/docs/volumes/manage.md), [Migrating data between volumes](/docs/volumes/migrate.md), [Mounting volumes](/docs/volumes/mount.md), [Upload data to volume](/docs/volumes/upload.md)

> Read, write, list, and remove files and directories in a volume with the SDK.

## Reading files

You can read files from a volume using the `readFile()` / `read_file()` method.

<CodeGroup>
```js title="JavaScript & TypeScript"
import { Volume } from 'e2b'

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

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

```python title="Python"
from e2b import Volume

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

content = volume.read_file('/path/to/file')
print(content)
```
</CodeGroup>

## Writing files

You can write files to a volume using the `writeFile()` / `write_file()` method.

<CodeGroup>
```js title="JavaScript & TypeScript"
import { Volume } from 'e2b'

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

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

```python title="Python"
from e2b import Volume

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

volume.write_file('/path/to/file', 'file content')
```
</CodeGroup>

## Creating directories

You can create directories in a volume using the `makeDir()` / `make_dir()` method.

<CodeGroup>
```js title="JavaScript & TypeScript"
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 })
```

```python title="Python"
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)
```
</CodeGroup>

## Listing directory contents

You can list the contents of a directory in a volume using the `list()` method.

<CodeGroup>
```js title="JavaScript & TypeScript"
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, ... },
// ]
```

```python title="Python"
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, ...),
# ]
```
</CodeGroup>

## Removing files or directories

You can remove files or directories from a volume using the `remove()` method.

<CodeGroup>
```js title="JavaScript & TypeScript"
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 })
```

```python title="Python"
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)
```
</CodeGroup>
