|
1 | | -# Code Interpreter template |
| 1 | +# Using custom sandbox with Code Interpreter SDK |
2 | 2 |
|
3 | | -This template runs a Jupyter server with a Python kernel. The jupyter server is started in `start_cmd`, this way the server will be already running when the sandbox is started. |
| 3 | +If you want to customize the Code Interprerter sandbox (e.g.: add a preinstlled package) you can do that by using a [custom sandbox template](https://e2b.dev/docs/sandbox/templates/overview). |
4 | 4 |
|
5 | | -## Customization |
| 5 | +1. Create custom sandbox by following [this guide](https://e2b.dev/docs/guide/custom-sandbox) |
6 | 6 |
|
7 | | -If you want to add another packages, another kernels or simply change some configuration and still use CodeInterpreter SDK, you will need to follow these steps: |
| 7 | +2. Use prebuilt [E2B Code Interpreter image](https://hub.docker.com/r/e2bdev/code-interpreter). Add this to your `e2b.Dockerfile` |
8 | 8 |
|
9 | | -1. Copy `jupyter_server_config.py`, `ipython_kernel_config.py` and `start-up.sh` from [this folder](./). |
10 | | -2. Add following commands in your Dockerfile |
| 9 | + ```Dockerfile |
| 10 | + FROM e2bdev/code-interpreter:latest |
| 11 | + ``` |
11 | 12 |
|
12 | | -```Dockerfile |
13 | | -# Installs jupyter server and kernel |
14 | | -RUN pip install jupyter-server ipykernel ipython |
15 | | -RUN ipython kernel install --name "python3" --user |
| 13 | +3. Copy [`start-up.sh`](./start-up.sh) to the same directory where's your `e2b.toml` |
16 | 14 |
|
17 | | -# Copies jupyter server config |
18 | | -COPY ./jupyter_server_config.py /home/user/.jupyter/ |
| 15 | +4. Run the following in the directory with `e2b.toml` |
| 16 | + ```sh |
| 17 | + e2b template build -c "/home/user/.jupyter/start-up.sh"` |
| 18 | + ``` |
19 | 19 |
|
20 | | -# Setups jupyter server |
21 | | -COPY ./start-up.sh /home/user/.jupyter/ |
22 | | -RUN chmod +x /home/user/.jupyter/start-up.sh |
23 | | -``` |
| 20 | +5. Use your custom sandbox with Code Interpreter SDK |
24 | 21 |
|
25 | | -3. Add the following option `-c "/home/user/.jupyter/start-up.sh"` to `e2b template build` command or add this line to your `e2b.toml`. |
| 22 | + **Python** |
| 23 | + ```python |
| 24 | + from e2b_code_interpreter import CodeInterpreter |
| 25 | + sandbox = CodeInterpreter("your-custom-sandbox-name") |
| 26 | + execution = sandbox.notebook.exec_cell("print('hello')") |
26 | 27 |
|
27 | | -```yaml |
28 | | -start_cmd = "/home/user/.jupyter/start-up.sh" |
29 | | -``` |
| 28 | + # Or you can use `with` |
| 29 | + with CodeInterpreter("your-custom-sandbox-name") as sandbox: |
| 30 | + execution = sandbox.notebook.exec_cell("print('hello')") |
| 31 | + ``` |
| 32 | + |
30 | 33 |
|
31 | | -## Use E2B code interpreter image |
32 | | - |
33 | | -Alternatively you can use prebuilt E2B Code Interpreter image. You can find it on Docker Hub: [e2b/code-interpreter](https://hub.docker.com/r/e2bdev/code-interpreter). You can simply write |
34 | | - |
35 | | -```Dockerfile |
36 | | -FROM e2bdev/code-interpreter:latest |
37 | | -``` |
38 | | - |
39 | | -instead of the step `1` and `2` above. You still HAVE TO add the `start_cmd` option to your `e2b.toml` or `e2b template build` command. |
| 34 | + **JavaScript/TypeScript** |
| 35 | + ```js |
| 36 | + import { CodeInterpreter } from '@e2b/code-interpreter' |
| 37 | + const sandbox = await CodeInterpreter.create('your-custom-sandbox-name') |
| 38 | + const execution = await sandbox.notebook.execCell('print("hello")') |
| 39 | + ``` |
0 commit comments