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

# Volume

### VolumeFileType

File type enum.

#### Enumeration Members

| Enumeration Member               | Value         |
| -------------------------------- | ------------- |
| <a id="directory" /> `DIRECTORY` | `"directory"` |
| <a id="file" /> `FILE`           | `"file"`      |
| <a id="symlink" /> `SYMLINK`     | `"symlink"`   |
| <a id="unknown" /> `UNKNOWN`     | `"unknown"`   |

## Classes

### Volume

Module for interacting with E2B volumes.

Create a `Volume` instance to interact with a volume by its ID,
or use the static methods to manage volumes.

#### Constructors

```ts theme={null}
new Volume(
   volumeId: string, 
   name: string, 
   token: string, 
   domain?: string, 
   debug?: boolean): Volume
```

Create a local Volume instance with no API call.

###### Parameters

| Parameter  | Type      | Description                |
| ---------- | --------- | -------------------------- |
| `volumeId` | `string`  | volume ID.                 |
| `name`     | `string`  | volume name.               |
| `token`    | `string`  | volume auth token.         |
| `domain`?  | `string`  | domain for the volume API. |
| `debug`?   | `boolean` | whether to use debug mode. |

###### Returns

`Volume`

#### Properties

| Property                       | Modifier   | Type      | Description                                                      |
| ------------------------------ | ---------- | --------- | ---------------------------------------------------------------- |
| <a id="debug" /> `debug?`      | `readonly` | `boolean` | Whether to use debug mode (connects to local volume API server). |
| <a id="domain" /> `domain?`    | `readonly` | `string`  | Domain used for constructing the volume API URL.                 |
| <a id="name" /> `name`         | `readonly` | `string`  | Volume name.                                                     |
| <a id="token" /> `token`       | `readonly` | `string`  | Volume auth token.                                               |
| <a id="volumeid" /> `volumeId` | `readonly` | `string`  | Volume ID.                                                       |

#### Methods

### exists()

```ts theme={null}
exists(path: string, opts?: VolumeApiOpts): Promise<boolean>
```

Check whether a file or directory exists.

Uses getInfo under the hood. Returns `true` if the path exists,
`false` if it does not (404). Other errors are rethrown.

###### Parameters

| Parameter | Type            | Description                    |
| --------- | --------------- | ------------------------------ |
| `path`    | `string`        | path to the file or directory. |
| `opts`?   | `VolumeApiOpts` | connection options.            |

###### Returns

`Promise`\<`boolean`>

`true` if the path exists, `false` otherwise.

### getInfo()

```ts theme={null}
getInfo(path: string, opts?: VolumeApiOpts): Promise<VolumeEntryStat>
```

Get information about a file or directory.

###### Parameters

| Parameter | Type            | Description                    |
| --------- | --------------- | ------------------------------ |
| `path`    | `string`        | path to the file or directory. |
| `opts`?   | `VolumeApiOpts` | connection options.            |

###### Returns

`Promise`\<`VolumeEntryStat`>

information about the entry.

### list()

```ts theme={null}
list(path: string, opts?: VolumeApiOpts & object): Promise<VolumeEntryStat[]>
```

List directory contents.

###### Parameters

| Parameter | Type                       | Description            |
| --------- | -------------------------- | ---------------------- |
| `path`    | `string`                   | path to the directory. |
| `opts`?   | `VolumeApiOpts` & `object` | connection options.    |

###### Returns

`Promise`\<`VolumeEntryStat`\[]>

list of entries in the directory.

### makeDir()

```ts theme={null}
makeDir(path: string, opts?: VolumeMetadataOptions & object & VolumeApiOpts): Promise<VolumeEntryStat>
```

Create a directory.

###### Parameters

| Parameter | Type                                                 | Description                      |
| --------- | ---------------------------------------------------- | -------------------------------- |
| `path`    | `string`                                             | path to the directory to create. |
| `opts`?   | `VolumeMetadataOptions` & `object` & `VolumeApiOpts` | connection options.              |

###### Returns

`Promise`\<`VolumeEntryStat`>

### readFile()

###### Call Signature

```ts theme={null}
readFile(path: string, opts?: VolumeApiOpts & object): Promise<string>
```

Read file content as a `string`.

You can pass `text`, `bytes`, `blob`, or `stream` to `opts.format` to change the return type.

###### Parameters

| Parameter | Type                       | Description         |
| --------- | -------------------------- | ------------------- |
| `path`    | `string`                   | path to the file.   |
| `opts`?   | `VolumeApiOpts` & `object` | connection options. |

###### Returns

`Promise`\<`string`>

file content as string

###### Call Signature

```ts theme={null}
readFile(path: string, opts?: VolumeApiOpts & object): Promise<Uint8Array<ArrayBufferLike>>
```

Read file content as a `Uint8Array`.

You can pass `text`, `bytes`, `blob`, or `stream` to `opts.format` to change the return type.

###### Parameters

| Parameter | Type                       | Description         |
| --------- | -------------------------- | ------------------- |
| `path`    | `string`                   | path to the file.   |
| `opts`?   | `VolumeApiOpts` & `object` | connection options. |

###### Returns

`Promise`\<`Uint8Array`\<`ArrayBufferLike`>>

file content as `Uint8Array`

###### Call Signature

```ts theme={null}
readFile(path: string, opts?: VolumeApiOpts & object): Promise<Blob>
```

Read file content as a `Blob`.

You can pass `text`, `bytes`, `blob`, or `stream` to `opts.format` to change the return type.

###### Parameters

| Parameter | Type                       | Description         |
| --------- | -------------------------- | ------------------- |
| `path`    | `string`                   | path to the file.   |
| `opts`?   | `VolumeApiOpts` & `object` | connection options. |

###### Returns

`Promise`\<`Blob`>

file content as `Blob`

###### Call Signature

```ts theme={null}
readFile(path: string, opts?: VolumeApiOpts & object): Promise<ReadableStream<Uint8Array<ArrayBufferLike>>>
```

Read file content as a `ReadableStream`.

You can pass `text`, `bytes`, `blob`, or `stream` to `opts.format` to change the return type.

###### Parameters

| Parameter | Type                       | Description         |
| --------- | -------------------------- | ------------------- |
| `path`    | `string`                   | path to the file.   |
| `opts`?   | `VolumeApiOpts` & `object` | connection options. |

###### Returns

`Promise`\<`ReadableStream`\<`Uint8Array`\<`ArrayBufferLike`>>>

file content as `ReadableStream`

### remove()

```ts theme={null}
remove(path: string, opts?: VolumeApiOpts): Promise<void>
```

Remove a file or directory.

###### Parameters

| Parameter | Type            | Description                              |
| --------- | --------------- | ---------------------------------------- |
| `path`    | `string`        | path to the file or directory to remove. |
| `opts`?   | `VolumeApiOpts` | connection options.                      |

###### Returns

`Promise`\<`void`>

### updateMetadata()

```ts theme={null}
updateMetadata(
   path: string, 
   metadata: VolumeMetadataOptions, 
opts?: VolumeApiOpts): Promise<VolumeEntryStat>
```

Update file or directory metadata.

###### Parameters

| Parameter  | Type                    | Description                          |
| ---------- | ----------------------- | ------------------------------------ |
| `path`     | `string`                | path to the file or directory.       |
| `metadata` | `VolumeMetadataOptions` | metadata to update (uid, gid, mode). |
| `opts`?    | `VolumeApiOpts`         | connection options.                  |

###### Returns

`Promise`\<`VolumeEntryStat`>

updated entry information.

### writeFile()

```ts theme={null}
writeFile(
   path: string, 
   data: 
  | string
  | ArrayBuffer
  | Blob
  | ReadableStream<Uint8Array<ArrayBufferLike>>, 
opts?: VolumeMetadataOptions & object & VolumeApiOpts): Promise<VolumeEntryStat>
```

Write content to a file.

Writing to a file that doesn't exist creates the file.

Writing to a file that already exists overwrites the file.

###### Parameters

| Parameter | Type                                                                                          | Description                                                                                  |
| --------- | --------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- |
| `path`    | `string`                                                                                      | path to the file.                                                                            |
| `data`    | \| `string` \| `ArrayBuffer` \| `Blob` \| `ReadableStream`\<`Uint8Array`\<`ArrayBufferLike`>> | data to write to the file. Data can be a string, `ArrayBuffer`, `Blob`, or `ReadableStream`. |
| `opts`?   | `VolumeMetadataOptions` & `object` & `VolumeApiOpts`                                          | connection options.                                                                          |

###### Returns

`Promise`\<`VolumeEntryStat`>

information about the written file

### connect()

```ts theme={null}
static connect(volumeId: string, opts?: ConnectionOpts): Promise<Volume>
```

Connect to an existing volume by ID.

###### Parameters

| Parameter  | Type             | Description         |
| ---------- | ---------------- | ------------------- |
| `volumeId` | `string`         | volume ID.          |
| `opts`?    | `ConnectionOpts` | connection options. |

###### Returns

`Promise`\<`Volume`>

Volume instance.

### create()

```ts theme={null}
static create(name: string, opts?: ConnectionOpts): Promise<Volume>
```

Create a new volume.

###### Parameters

| Parameter | Type             | Description         |
| --------- | ---------------- | ------------------- |
| `name`    | `string`         | name of the volume. |
| `opts`?   | `ConnectionOpts` | connection options. |

###### Returns

`Promise`\<`Volume`>

new Volume instance.

### destroy()

```ts theme={null}
static destroy(volumeId: string, opts?: ConnectionOpts): Promise<boolean>
```

Destroy a volume.

###### Parameters

| Parameter  | Type             | Description         |
| ---------- | ---------------- | ------------------- |
| `volumeId` | `string`         | volume ID.          |
| `opts`?    | `ConnectionOpts` | connection options. |

###### Returns

`Promise`\<`boolean`>

### getInfo()

```ts theme={null}
static getInfo(volumeId: string, opts?: ConnectionOpts): Promise<VolumeAndToken>
```

Get volume information.

###### Parameters

| Parameter  | Type             | Description         |
| ---------- | ---------------- | ------------------- |
| `volumeId` | `string`         | volume ID.          |
| `opts`?    | `ConnectionOpts` | connection options. |

###### Returns

`Promise`\<`VolumeAndToken`>

volume information.

### list()

```ts theme={null}
static list(opts?: ConnectionOpts): Promise<VolumeInfo[]>
```

List all volumes.

###### Parameters

| Parameter | Type             | Description         |
| --------- | ---------------- | ------------------- |
| `opts`?   | `ConnectionOpts` | connection options. |

###### Returns

`Promise`\<`VolumeInfo`\[]>

list of volume information.

***

### VolumeConnectionConfig

#### Constructors

```ts theme={null}
new VolumeConnectionConfig(volume: Volume, opts?: VolumeApiOpts): VolumeConnectionConfig
```

###### Parameters

| Parameter | Type            |
| --------- | --------------- |
| `volume`  | `Volume`        |
| `opts`?   | `VolumeApiOpts` |

###### Returns

`VolumeConnectionConfig`

#### Properties

| Property                                        | Modifier   | Type                          |
| ----------------------------------------------- | ---------- | ----------------------------- |
| <a id="apiurl" /> `apiUrl`                      | `readonly` | `string`                      |
| <a id="debug-1" /> `debug`                      | `readonly` | `boolean`                     |
| <a id="domain-1" /> `domain`                    | `readonly` | `string`                      |
| <a id="headers" /> `headers?`                   | `readonly` | `Record`\<`string`, `string`> |
| <a id="logger" /> `logger?`                     | `readonly` | `Logger`                      |
| <a id="requesttimeoutms" /> `requestTimeoutMs?` | `readonly` | `number`                      |
| <a id="token-1" /> `token?`                     | `readonly` | `string`                      |

#### Methods

### getSignal()

```ts theme={null}
getSignal(requestTimeoutMs?: number): undefined | AbortSignal
```

###### Parameters

| Parameter           | Type     |
| ------------------- | -------- |
| `requestTimeoutMs`? | `number` |

###### Returns

`undefined` | `AbortSignal`

## Interfaces

### VolumeApiOpts

#### Properties

### domain?

```ts theme={null}
optional domain: string;
```

Domain to use for the volume API.

###### Default

E2B\_DOMAIN // environment variable or `e2b.app`

### headers?

```ts theme={null}
optional headers: Record<string, string>;
```

Additional headers to send with the request.

### logger?

```ts theme={null}
optional logger: Logger;
```

Logger to use for logging messages. It can accept any object that implements `Logger` interface—for example, console.

### requestTimeoutMs?

```ts theme={null}
optional requestTimeoutMs: number;
```

Timeout for requests to the API in **milliseconds**.

###### Default

```ts theme={null}
60_000 // 60 seconds
```

### token?

```ts theme={null}
optional token: string;
```

E2B API key to use for authentication.

###### Default

```ts theme={null}
E2B_API_KEY // environment variable
```

## Type Aliases

### VolumeAndToken

```ts theme={null}
type VolumeAndToken = VolumeInfo & object;
```

Information about a volume and its auth token.

#### Type declaration

| Name    | Type     | Description        |
| ------- | -------- | ------------------ |
| `token` | `string` | Volume auth token. |

***

### VolumeEntryStat

```ts theme={null}
type VolumeEntryStat = Omit<VolumeApiComponents["schemas"]["VolumeEntryStat"], "atime" | "mtime" | "ctime" | "type"> & object;
```

Volume entry stat with dates converted to Date objects.

#### Type declaration

| Name    | Type             | Description                         |
| ------- | ---------------- | ----------------------------------- |
| `atime` | `Date`           | Access time as a Date object.       |
| `ctime` | `Date`           | Creation time as a Date object.     |
| `mtime` | `Date`           | Modification time as a Date object. |
| `type`  | `VolumeFileType` | File type.                          |

***

### VolumeInfo

```ts theme={null}
type VolumeInfo = object;
```

Information about a volume.

#### Type declaration

| Name                             | Type     | Description  |
| -------------------------------- | -------- | ------------ |
| <a id="name-1" /> `name`         | `string` | Volume name. |
| <a id="volumeid-1" /> `volumeId` | `string` | Volume ID.   |

***

### VolumeMetadataOptions

```ts theme={null}
type VolumeMetadataOptions = object;
```

Options for updating file metadata.

#### Type declaration

| Name                    | Type     | Description                        |
| ----------------------- | -------- | ---------------------------------- |
| <a id="gid" /> `gid`?   | `number` | Group ID of the file or directory. |
| <a id="mode" /> `mode`? | `number` | Mode of the file or directory.     |
| <a id="uid" /> `uid`?   | `number` | User ID of the file or directory.  |

***

### VolumeWriteOptions

```ts theme={null}
type VolumeWriteOptions = VolumeMetadataOptions & object;
```

Options for file and directory operations.

#### Type declaration

| Name     | Type      | Description                                                                                                     |
| -------- | --------- | --------------------------------------------------------------------------------------------------------------- |
| `force`? | `boolean` | For makeDir: Create parent directories if they don't exist. For writeFile: Force overwrite of an existing file. |
