Skip to content

Commit f209990

Browse files
authored
Added docs on Volumes (#118)
* added volume docs * updated docs * diagram * added examples, note * added clarification * removed diagram controls * remove the diagram controls * added standalone diagram * updated volumes docs
1 parent 5a439f1 commit f209990

8 files changed

Lines changed: 663 additions & 0 deletions

File tree

docs.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,18 @@
166166
"docs/filesystem/download"
167167
]
168168
},
169+
{
170+
"group": "Volumes",
171+
"pages": [
172+
"docs/volumes",
173+
"docs/volumes/manage",
174+
"docs/volumes/mount",
175+
"docs/volumes/read-write",
176+
"docs/volumes/info",
177+
"docs/volumes/upload",
178+
"docs/volumes/download"
179+
]
180+
},
169181
{
170182
"group": "Commands",
171183
"pages": [

docs/volumes.mdx

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
---
2+
title: "Volumes"
3+
sidebarTitle: Overview
4+
---
5+
6+
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.
7+
8+
**One volume shared across multiple sandboxes**
9+
10+
```mermaid actions={false}
11+
graph LR
12+
V1[Volume A] --- S1[Sandbox 1]
13+
V1 --- S2[Sandbox 2]
14+
V1 --- S3[Sandbox 3]
15+
```
16+
17+
**Each sandbox with its own volume**
18+
19+
```mermaid actions={false}
20+
graph LR
21+
V2[Volume A] --- S4[Sandbox 1]
22+
V3[Volume B] --- S5[Sandbox 2]
23+
```
24+
25+
**Standalone usage via SDK**
26+
27+
```mermaid actions={false}
28+
graph LR
29+
SDK[SDK] --- V4[Volume A]
30+
SDK --- V5[Volume B]
31+
```
32+
33+
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.
34+
35+
With E2B SDK you can:
36+
- [Manage volumes.](/docs/volumes/manage)
37+
- [Mount volumes to sandboxes.](/docs/volumes/mount)
38+
- [Read and write files to a volume.](/docs/volumes/read-write)
39+
- [Get file and directory metadata.](/docs/volumes/info)
40+
- [Upload data to a volume.](/docs/volumes/upload)
41+
- [Download data from a volume.](/docs/volumes/download)
42+
43+
## Example
44+
45+
<CodeGroup>
46+
```js JavaScript & TypeScript
47+
import { Volume, Sandbox } from 'e2b'
48+
49+
const volume = await Volume.create('my-volume')
50+
51+
const sandbox = await Sandbox.create({
52+
volumeMounts: {
53+
'/mnt/my-data': volume,
54+
},
55+
})
56+
```
57+
```python Python
58+
from e2b import Volume, Sandbox
59+
60+
volume = Volume.create('my-volume')
61+
62+
sandbox = Sandbox.create(
63+
volume_mounts={
64+
'/mnt/my-data': volume,
65+
},
66+
)
67+
```
68+
</CodeGroup>

docs/volumes/download.mdx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
title: "Download data from volume"
3+
sidebarTitle: Download data
4+
---
5+
6+
You can download data from a volume using the `readFile()` / `read_file()` method.
7+
8+
<CodeGroup>
9+
```js JavaScript & TypeScript
10+
import fs from 'fs'
11+
import { Volume } from 'e2b'
12+
13+
const volume = await Volume.create('my-volume')
14+
15+
// Read file from volume
16+
const content = await volume.readFile('/path/in/volume')
17+
// Write file to local filesystem
18+
fs.writeFileSync('/local/path', content)
19+
```
20+
```python Python
21+
from e2b import Volume
22+
23+
volume = Volume.create('my-volume')
24+
25+
# Read file from volume
26+
content = volume.read_file('/path/in/volume')
27+
# Write file to local filesystem
28+
with open('/local/path', 'w') as file:
29+
file.write(content)
30+
```
31+
</CodeGroup>

docs/volumes/info.mdx

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
---
2+
title: "Get information about a file or directory"
3+
sidebarTitle: File & directory metadata
4+
---
5+
6+
You can get information about a file or directory in a volume using the `getInfo()` / `get_info()` method.
7+
8+
### Getting information about a file
9+
10+
<CodeGroup>
11+
```js JavaScript & TypeScript
12+
import { Volume } from 'e2b'
13+
14+
const volume = await Volume.create('my-volume')
15+
16+
// Create a new file
17+
await volume.writeFile('/test_file.txt', 'Hello, world!')
18+
19+
// Get information about the file
20+
const info = await volume.getInfo('/test_file.txt')
21+
22+
console.log(info)
23+
// {
24+
// name: 'test_file.txt',
25+
// type: 'file',
26+
// path: '/test_file.txt',
27+
// size: 13,
28+
// mode: 0o644,
29+
// uid: 0,
30+
// gid: 0,
31+
// atime: 2025-05-26T12:00:00.000Z,
32+
// mtime: 2025-05-26T12:00:00.000Z,
33+
// ctime: 2025-05-26T12:00:00.000Z,
34+
// }
35+
```
36+
```python Python
37+
from e2b import Volume
38+
39+
volume = Volume.create('my-volume')
40+
41+
# Create a new file
42+
volume.write_file('/test_file.txt', 'Hello, world!')
43+
44+
# Get information about the file
45+
info = volume.get_info('/test_file.txt')
46+
47+
print(info)
48+
# VolumeEntryStat(
49+
# name='test_file.txt',
50+
# type_='file',
51+
# path='/test_file.txt',
52+
# size=13,
53+
# mode=0o644,
54+
# uid=0,
55+
# gid=0,
56+
# atime=datetime(2025, 5, 26, 12, 0, 0),
57+
# mtime=datetime(2025, 5, 26, 12, 0, 0),
58+
# ctime=datetime(2025, 5, 26, 12, 0, 0),
59+
# )
60+
```
61+
</CodeGroup>
62+
63+
### Getting information about a directory
64+
65+
<CodeGroup>
66+
```js JavaScript & TypeScript
67+
import { Volume } from 'e2b'
68+
69+
const volume = await Volume.create('my-volume')
70+
71+
// Create a new directory
72+
await volume.makeDir('/test_dir')
73+
74+
// Get information about the directory
75+
const info = await volume.getInfo('/test_dir')
76+
77+
console.log(info)
78+
// {
79+
// name: 'test_dir',
80+
// type: 'directory',
81+
// path: '/test_dir',
82+
// size: 0,
83+
// mode: 0o755,
84+
// uid: 0,
85+
// gid: 0,
86+
// atime: 2025-05-26T12:00:00.000Z,
87+
// mtime: 2025-05-26T12:00:00.000Z,
88+
// ctime: 2025-05-26T12:00:00.000Z,
89+
// }
90+
```
91+
```python Python
92+
from e2b import Volume
93+
94+
volume = Volume.create('my-volume')
95+
96+
# Create a new directory
97+
volume.make_dir('/test_dir')
98+
99+
# Get information about the directory
100+
info = volume.get_info('/test_dir')
101+
102+
print(info)
103+
# VolumeEntryStat(
104+
# name='test_dir',
105+
# type_='directory',
106+
# path='/test_dir',
107+
# size=0,
108+
# mode=0o755,
109+
# uid=0,
110+
# gid=0,
111+
# atime=datetime(2025, 5, 26, 12, 0, 0),
112+
# mtime=datetime(2025, 5, 26, 12, 0, 0),
113+
# ctime=datetime(2025, 5, 26, 12, 0, 0),
114+
# )
115+
```
116+
</CodeGroup>
117+
118+
### Checking if a path exists
119+
120+
You can check whether a file or directory exists in a volume using the `exists()` method.
121+
122+
<CodeGroup>
123+
```js JavaScript & TypeScript
124+
import { Volume } from 'e2b'
125+
126+
const volume = await Volume.create('my-volume')
127+
128+
const fileExists = await volume.exists('/test_file.txt')
129+
console.log(fileExists) // true or false
130+
```
131+
```python Python
132+
from e2b import Volume
133+
134+
volume = Volume.create('my-volume')
135+
136+
file_exists = volume.exists('/test_file.txt')
137+
print(file_exists) # True or False
138+
```
139+
</CodeGroup>
140+
141+
### Updating metadata
142+
143+
You can update file or directory metadata such as user ID, group ID, and permissions mode using the `updateMetadata()` / `update_metadata()` method.
144+
145+
<CodeGroup>
146+
```js JavaScript & TypeScript
147+
import { Volume } from 'e2b'
148+
149+
const volume = await Volume.create('my-volume')
150+
151+
await volume.writeFile('/test_file.txt', 'Hello, world!')
152+
153+
const updated = await volume.updateMetadata('/test_file.txt', { uid: 1000, gid: 1000, mode: 0o600 })
154+
155+
console.log(updated)
156+
// {
157+
// name: 'test_file.txt',
158+
// type: 'file',
159+
// path: '/test_file.txt',
160+
// size: 13,
161+
// mode: 0o600,
162+
// uid: 1000,
163+
// gid: 1000,
164+
// ...
165+
// }
166+
```
167+
```python Python
168+
from e2b import Volume
169+
170+
volume = Volume.create('my-volume')
171+
172+
volume.write_file('/test_file.txt', 'Hello, world!')
173+
174+
updated = volume.update_metadata('/test_file.txt', uid=1000, gid=1000, mode=0o600)
175+
176+
print(updated)
177+
# VolumeEntryStat(
178+
# name='test_file.txt',
179+
# type_='file',
180+
# path='/test_file.txt',
181+
# size=13,
182+
# mode=0o600,
183+
# uid=1000,
184+
# gid=1000,
185+
# ...
186+
# )
187+
```
188+
</CodeGroup>

0 commit comments

Comments
 (0)