> ## Documentation Index
> Fetch the complete documentation index at: https://e2b.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Read & write files

> 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 JavaScript & TypeScript theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
  import { Volume } from 'e2b'

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

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

  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
  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 JavaScript & TypeScript theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
  import { Volume } from 'e2b'

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

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

  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
  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 JavaScript & TypeScript theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
  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 Python theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
  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 JavaScript & TypeScript theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
  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 Python theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
  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 JavaScript & TypeScript theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
  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 Python theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
  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>
