Skip to content

Commit 43c8949

Browse files
authored
fix: update install custom packages tutorial to use the v2 build system (#58)
1 parent 15fc7e5 commit 43c8949

File tree

1 file changed

+90
-58
lines changed

1 file changed

+90
-58
lines changed

docs/quickstart/install-custom-packages.mdx

Lines changed: 90 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -13,96 +13,128 @@ There are two ways to install custom packages in the E2B Sandbox.
1313

1414
Use this option if you know beforehand what packages you need in the sandbox.
1515

16-
Prerequisites:
17-
- E2B CLI
18-
- Docker running
19-
2016
<Note>
21-
Custom sandbox template is a Docker image that we automatically convert to a sandbox that you can then start with our SDK.
17+
Sandbox templates allow you to define custom sandboxes with preinstalled packages and configurations.
2218
</Note>
2319

24-
25-
### 1. Install E2B CLI
26-
27-
**Using Homebrew (on macOS)**
20+
### 1. Install the E2B SDK
2821

2922
<CodeGroup>
30-
```bash Terminal
31-
brew install e2b
23+
```bash JavaScript & TypeScript
24+
npm install e2b dotenv
25+
```
26+
```bash Python
27+
pip install e2b python-dotenv
3228
```
3329
</CodeGroup>
3430

35-
**Using NPM**
31+
Create a `.env` file with your API key:
32+
```bash
33+
E2B_API_KEY=e2b_***
34+
```
35+
36+
### 2. Create a template file
37+
38+
Define your custom template with the packages you need.
3639

3740
<CodeGroup>
38-
```bash Terminal
39-
npm i -g @e2b/cli
41+
```typescript JavaScript & TypeScript
42+
// template.ts
43+
import { Template } from "e2b";
44+
45+
export const template = Template()
46+
.fromTemplate("code-interpreter-v1")
47+
.pipInstall(['cowsay']) // Install Python packages
48+
.npmInstall(['cowsay']); // Install Node.js packages
4049
```
41-
</CodeGroup>
4250

43-
### 2. Login to E2B CLI
44-
Before you can create a custom sandbox, you need to login to E2B CLI.
45-
<CodeGroup>
46-
```bash Terminal
47-
e2b auth login
51+
```python Python
52+
# template.py
53+
from e2b import Template
54+
55+
template = (
56+
Template()
57+
.from_template("code-interpreter-v1")
58+
.pip_install(['cowsay']) # Install Python packages
59+
.npm_install(['cowsay']) # Install Node.js packages
60+
)
4861
```
4962
</CodeGroup>
5063

51-
### 2. Initialize a sandbox template
64+
### 3. Create a build script
65+
5266
<CodeGroup>
53-
```bash Terminal
54-
e2b template init
67+
```typescript JavaScript & TypeScript
68+
// build.prod.ts
69+
import "dotenv/config";
70+
import { Template, defaultBuildLogger } from "e2b";
71+
import { template } from "./template";
72+
73+
async function main() {
74+
await Template.build(template, {
75+
alias: "custom-packages",
76+
cpuCount: 2,
77+
memoryMB: 2048,
78+
onBuildLogs: defaultBuildLogger(),
79+
});
80+
}
81+
82+
main().catch(console.error);
83+
```
84+
85+
```python Python
86+
# build.prod.py
87+
from dotenv import load_dotenv
88+
from e2b import Template, default_build_logger
89+
from template import template
90+
91+
load_dotenv()
92+
93+
if __name__ == '__main__':
94+
Template.build(
95+
template,
96+
alias="custom-packages",
97+
cpu_count=2,
98+
memory_mb=2048,
99+
on_build_logs=default_build_logger(),
100+
)
55101
```
56102
</CodeGroup>
57103

58-
### 3. Specify the packages you need in `e2b.Dockerfile`
59-
Edit the E2B Dockerfile to install the packages you need.
104+
### 4. Build the template
60105

61-
<Note>
62-
You need to use the `e2bdev/code-interpreter:latest` base image.
63-
</Note>
106+
Run the build script to create your custom template:
64107

65108
<CodeGroup>
66-
```bash e2b.Dockerfile
67-
FROM e2bdev/code-interpreter:latest
68-
69-
RUN pip install cowsay
70-
RUN npm install cowsay
109+
```bash JavaScript & TypeScript
110+
npx tsx build.prod.ts
71111
```
72-
</CodeGroup>
73112

74-
### 4. Build the sandbox template
75-
Run the following command to build the sandbox template.
76-
<CodeGroup>
77-
```bash Terminal
78-
e2b template build -c "/root/.jupyter/start-up.sh"
113+
```bash Python
114+
python build.prod.py
79115
```
80116
</CodeGroup>
81117

82-
This will take a while, as it convert the Docker image to a sandbox which is a small VM.
83-
At the end of the process you will see the sandbox ID like this:
84-
```
85-
Running postprocessing. It can take up to few minutes.
118+
This will build your template and you'll see build logs in the console.
86119

87-
Postprocessing finished.
120+
### 5. Use your custom sandbox
88121

89-
✅ Building sandbox template YOUR_TEMPLATE_ID finished.
90-
```
122+
Now you can create sandboxes from your custom template:
91123

92-
### 5. Start your custom sandbox
93-
Now you can pass the template ID to the SDK to start your custom sandbox.
94124
<CodeGroup>
95125
```js JavaScript & TypeScript
96-
import { Sandbox } from '@e2b/code-interpreter'
126+
import { Sandbox } from 'e2b'
127+
128+
const sbx = await Sandbox.create("custom-packages")
97129

98-
const sbx = Sandbox.create({
99-
template: 'YOUR_TEMPLATE_ID',
100-
})
130+
// Your packages are already installed and ready to use
101131
```
102132
```python Python
103-
from e2b_code_interpreter import Sandbox
133+
from e2b import Sandbox
134+
135+
sbx = Sandbox.create("custom-packages")
104136

105-
sbx = Sandbox.create(template='YOUR_TEMPLATE_ID')
137+
# Your packages are already installed and ready to use
106138
```
107139
</CodeGroup>
108140

@@ -122,7 +154,7 @@ When you start a new sandbox instance, the packages are not be available.
122154
```js JavaScript & TypeScript
123155
import { Sandbox } from '@e2b/code-interpreter'
124156

125-
const sbx = Sandbox.create()
157+
const sbx = await Sandbox.create()
126158
sbx.commands.run('pip install cowsay') // This will install the cowsay package
127159
sbx.runCode(`
128160
import cowsay
@@ -147,7 +179,7 @@ sbx.run_code("""
147179
```js JavaScript & TypeScript
148180
import { Sandbox } from '@e2b/code-interpreter'
149181

150-
const sbx = Sandbox.create()
182+
const sbx = await Sandbox.create()
151183
sbx.commands.run('npm install cowsay') // This will install the cowsay package
152184
sbx.runCode(`
153185
const cowsay = require('cowsay')
@@ -177,7 +209,7 @@ For example, to install `curl` and `git`, you can use the following commands:
177209
```js JavaScript & TypeScript
178210
import { Sandbox } from '@e2b/code-interpreter'
179211

180-
const sbx = Sandbox.create()
212+
const sbx = await Sandbox.create()
181213
await sbx.commands.run('apt-get update && apt-get install -y curl git')
182214
```
183215
```python Python
@@ -186,4 +218,4 @@ from e2b_code_interpreter import Sandbox
186218
sbx = Sandbox.create()
187219
sbx.commands.run("apt-get update && apt-get install -y curl git")
188220
```
189-
</CodeGroup>
221+
</CodeGroup>

0 commit comments

Comments
 (0)