Skip to content

Commit 2935716

Browse files
committed
updated readme
1 parent cc98720 commit 2935716

File tree

1 file changed

+43
-31
lines changed

1 file changed

+43
-31
lines changed

template/README.md

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,57 @@
11
# Using custom sandbox with Code Interpreter SDK
22

3-
If you want to customize the Code Interprerter sandbox (e.g.: add a preinstalled package) you can do that by using a [custom sandbox template](https://e2b.dev/docs/sandbox-template).
4-
3+
If you want to customize the Code Interprerter sandbox (e.g.: add a preinstalled package) you can do that by creating a [custom sandbox template](https://e2b.dev/docs/template/quickstart).
54

65
## Step-by-step guide
7-
1. Create custom sandbox by following [this guide](https://e2b.dev/docs/sandbox-template)
86

9-
2. Use prebuilt [E2B Code Interpreter image](https://hub.docker.com/r/e2bdev/code-interpreter) by replacing the `FROM` command in your `e2b.Dockerfile` with following
7+
1. Install E2B SDK
8+
9+
```
10+
pip install e2b dotenv
11+
```
12+
13+
2. Create a custom sandbox template:
14+
15+
**template.py**
16+
17+
```python
18+
from e2b import Template
19+
20+
template = Template().from_template("code-interpreter-v1")
21+
```
22+
23+
3. Create a build script:
1024

11-
```Dockerfile
12-
FROM e2bdev/code-interpreter:latest
13-
```
25+
**build.py**
1426

15-
3. Copy [`start-up.sh`](./start-up.sh) to the same directory where's your `e2b.toml`
27+
```python
28+
from dotenv import load_dotenv
29+
from .template import template
30+
from e2b import Template, default_build_logger
1631

17-
4. Run the following in the same directory where's your `e2b.toml`
18-
```sh
19-
e2b template build -c "/root/.jupyter/start-up.sh"
20-
```
32+
load_dotenv()
2133

22-
5. Use your custom sandbox with Code Interpreter SDK
34+
Template.build(
35+
template,
36+
alias="code-interpreter-custom",
37+
cpu_count=2,
38+
memory_mb=2048,
39+
on_build_logs=default_build_logger(),
40+
)
41+
```
2342

24-
**Python**
25-
```python
26-
from e2b_code_interpreter import Sandbox
27-
sandbox = Sandbox.create(template="your-custom-sandbox-name")
28-
execution = sandbox.run_code("print('hello')")
29-
sandbox.kill()
43+
3. Build the template:
3044

31-
# Or you can use `with` which handles closing the sandbox for you
32-
with Sandbox.create(template="your-custom-sandbox-name") as sandbox:
33-
execution = sandbox.run_code("print('hello')")
34-
```
35-
45+
```
46+
python build.py
47+
```
3648

37-
**JavaScript/TypeScript**
49+
4. Use the custom template:
3850

39-
```js
40-
import {Sandbox} from '@e2b/code-interpreter'
51+
```python
52+
from e2b import Sandbox
4153

42-
const sandbox = await Sandbox.create({template: 'your-custom-sandbox-name'})
43-
const execution = await sandbox.runCode('print("hello")')
44-
await sandbox.kill()
45-
```
54+
sbx = Sandbox.create(template="code-interpreter-custom")
55+
execution = sbx.run_code("print('Hello, World!')")
56+
print(execution.logs.stdout)
57+
```

0 commit comments

Comments
 (0)