Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,16 @@
"docs/filesystem/download"
]
},
{
"group": "Volumes",
"pages": [
"docs/volumes",
"docs/volumes/read-write",
"docs/volumes/info",
"docs/volumes/upload",
"docs/volumes/download"
]
},
{
"group": "Commands",
"pages": [
Expand Down
181 changes: 181 additions & 0 deletions docs/volumes.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
---
title: "Volumes"
sidebarTitle: Overview
---

Volumes provide persistent storage that exists independently of sandbox lifecycles. Data written to a volume persists even after a sandbox is shut down, and volumes can be mounted to multiple sandboxes over time.

**One volume shared across multiple sandboxes**

```mermaid actions={false}
graph LR
V1[Volume A] --- S1[Sandbox 1]
V1 --- S2[Sandbox 2]
V1 --- S3[Sandbox 3]
```

**Each sandbox with its own volume**

```mermaid actions={false}
graph LR
V2[Volume A] --- S4[Sandbox 1]
V3[Volume B] --- S5[Sandbox 2]
```

When a volume is mounted to a sandbox, files can be read and written directly at the mount path. The SDK methods are meant to be used when the volume is not mounted to any sandbox.

With E2B SDK you can:
- [Read and write files to a volume.](/docs/volumes/read-write)
- [Get file and directory metadata.](/docs/volumes/info)
- [Upload data to a volume.](/docs/volumes/upload)
- [Download data from a volume.](/docs/volumes/download)

## Create a volume

<Note>
Volume names can only contain letters, numbers, and hyphens.
</Note>

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

const volume = await Volume.create('my-volume')
console.log(volume.volumeId) // Volume ID
console.log(volume.name) // 'my-volume'
```
```python Python
from e2b import Volume

volume = Volume.create('my-volume')
print(volume.volume_id) # Volume ID
print(volume.name) # 'my-volume'
```
</CodeGroup>

## Connect to an existing volume

You can connect to an existing volume by its ID using the `connect()` method.

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

const volume = await Volume.connect('volume-id')
console.log(volume.volumeId) // Volume ID
console.log(volume.name) // Volume name
```
```python Python
from e2b import Volume

volume = Volume.connect('volume-id')
print(volume.volume_id) # Volume ID
print(volume.name) # Volume name
```
</CodeGroup>

## Mount a volume to a sandbox

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.

<CodeGroup>
```js JavaScript & TypeScript
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 sandbox2 = 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!')
```
```python Python
from e2b import Volume, Sandbox

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

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

# Or pass the volume name directly
sandbox2 = Sandbox.create(
volume_mounts={
'/mnt/my-data': 'my-volume',
},
)

# Files written to /mnt/my-data inside the sandbox are persisted in the volume
sandbox.files.write('/mnt/my-data/hello.txt', 'Hello, world!')
```
</CodeGroup>

## List volumes

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

const volumes = await Volume.list()
console.log(volumes)
// [{ volumeId: '...', name: 'my-volume' }, ...]
```
```python Python
from e2b import Volume

volumes = Volume.list()
print(volumes)
# [VolumeInfo(volume_id='...', name='my-volume'), ...]
```
</CodeGroup>

## Get volume info

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

const info = await Volume.getInfo('volume-id')
console.log(info)
// { volumeId: '...', name: 'my-volume' }
```
```python Python
from e2b import Volume

info = Volume.get_info('volume-id')
print(info)
# VolumeInfo(volume_id='...', name='my-volume')
```
</CodeGroup>

## Destroy a volume

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

const success = await Volume.destroy('volume-id')
console.log(success) // true
```
```python Python
from e2b import Volume

success = Volume.destroy('volume-id')
print(success) # True
```
</CodeGroup>
31 changes: 31 additions & 0 deletions docs/volumes/download.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
title: "Download data from volume"
sidebarTitle: Download data
---

You can download data from a volume using the `readFile()` / `read_file()` method.

<CodeGroup>
```js JavaScript & TypeScript
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)
```
```python Python
from e2b import Volume

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

# Read file from volume
content = volume.read_file('/path/in/volume')
# Write file to local filesystem
with open('/local/path', 'w') as file:
file.write(content)
```
</CodeGroup>
Loading