Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
1bb61b0
initial commit
mishushakov Nov 3, 2025
3b9ce19
cursor suggestions
mishushakov Nov 3, 2025
856b37f
updated
mishushakov Nov 3, 2025
4a1a7bc
fix template
mishushakov Nov 3, 2025
3bb1ac5
fmt
mishushakov Nov 3, 2025
748968a
removed unused env vars
mishushakov Nov 3, 2025
ef6597a
updated ci
mishushakov Nov 3, 2025
be9b047
python build ci test
mishushakov Nov 3, 2025
cf7a995
dependencies
mishushakov Nov 3, 2025
af0c3c0
removed dotenv from ci
mishushakov Nov 3, 2025
a6446d0
add capture for template id, build id
mishushakov Nov 3, 2025
66eb9fb
fixes java test, template name
mishushakov Nov 3, 2025
8691060
lint
mishushakov Nov 3, 2025
aac4798
added changeset
mishushakov Nov 3, 2025
c2e9f10
readded cleanup
mishushakov Nov 3, 2025
46e4027
updated release CI
mishushakov Nov 3, 2025
cc98720
updated dockerhub push tag
mishushakov Nov 3, 2025
2935716
updated readme
mishushakov Nov 3, 2025
80aed03
remove poetry from template build ci
mishushakov Nov 3, 2025
7673c9f
generate template alias before test run
mishushakov Nov 4, 2025
29d10b6
updated workflow
mishushakov Nov 4, 2025
131da7c
updated generated template alias for clarity
mishushakov Nov 4, 2025
9e78917
updated output
mishushakov Nov 4, 2025
2bbcf88
removed unused build_id output
mishushakov Nov 4, 2025
36529ce
corrected outputs
mishushakov Nov 4, 2025
13de536
pin r, java, deno versions
mishushakov Nov 5, 2025
33a5c22
install java from source, keep java 11
mishushakov Nov 5, 2025
7e8d74a
make sure python & js kernels always installed
mishushakov Nov 5, 2025
101ab77
fixes java home
mishushakov Nov 5, 2025
e97ad19
make kernels set
mishushakov Nov 6, 2025
ea46150
fixed typo
mishushakov Nov 6, 2025
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
5 changes: 5 additions & 0 deletions .changeset/empty-wasps-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@e2b/code-interpreter-template': minor
---

updated template to new SDK
35 changes: 20 additions & 15 deletions .github/workflows/build_test_template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Build Template
on:
workflow_call:
secrets:
E2B_TESTS_ACCESS_TOKEN:
E2B_API_KEY:
required: true
inputs:
E2B_DOMAIN:
Expand All @@ -22,7 +22,7 @@ jobs:
name: Build E2B Template
runs-on: ubuntu-latest
outputs:
template_id: ${{ steps.build-template.outputs.template_id }}
template_id: ${{ steps.generate-template-id.outputs.template_id }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand All @@ -34,22 +34,27 @@ jobs:
echo "Version: $VERSION"
sed -i "s/e2b_charts/e2b_charts==${VERSION}/g" requirements.txt

- name: Install E2B CLI
run: npm install -g @e2b/cli
- uses: actions/setup-python@v6
with:
python-version: '3.13'

- name: Install development dependencies
working-directory: ./template
run: pip install -r requirements-dev.txt

- name: Generate Template ID
id: generate-template-id
run: |
E2B_TESTS_TEMPLATE=e2b-code-interpreter-ci-$(uuidgen)
echo "Generated Template ID: $E2B_TESTS_TEMPLATE"
echo "template_id=$E2B_TESTS_TEMPLATE" >> $GITHUB_OUTPUT

- name: Build E2B template
id: build-template
run: |
rm -f e2b.toml
e2b template build --memory-mb 1024 -c "/root/.jupyter/start-up.sh" -d "Dockerfile"
TEMPLATE_ID=$(grep "template_id" e2b.toml | cut -d '"' -f 2)
echo "Captured Template ID: $TEMPLATE_ID"
echo "template_id=$TEMPLATE_ID" >> $GITHUB_OUTPUT
working-directory: ./template
run: |
python build_ci.py
env:
E2B_ACCESS_TOKEN: ${{ secrets.E2B_TESTS_ACCESS_TOKEN }}
E2B_API_KEY: ${{ secrets.E2B_API_KEY }}
E2B_DOMAIN: ${{ inputs.E2B_DOMAIN }}

- name: Output template ID
run: |
echo "Template ID from step output: ${{ steps.build-template.outputs.template_id }}"
E2B_TESTS_TEMPLATE: ${{ steps.generate-template-id.outputs.template_id }}
2 changes: 1 addition & 1 deletion .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
build-template:
uses: ./.github/workflows/build_test_template.yml
secrets:
E2B_TESTS_ACCESS_TOKEN: ${{ secrets.E2B_TESTS_ACCESS_TOKEN }}
E2B_API_KEY: ${{ secrets.E2B_API_KEY }}
with:
E2B_DOMAIN: ${{ vars.E2B_DOMAIN }}
js-sdk:
Expand Down
32 changes: 20 additions & 12 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,13 @@ jobs:

sed -i "s/e2b_charts/e2b_charts==${VERSION}/g" requirements.txt

- name: Build Docker image
uses: docker/build-push-action@v6
with:
context: ./template
push: true
platforms: linux/amd64
tags: ${{ secrets.DOCKERHUB_USERNAME }}/code-interpreter:latest
- name: Build and push to DockerHub
working-directory: ./template
run: |
python build_docker.py | docker buildx build \
--platform linux/amd64 \
--push \
--tag ${{ secrets.DOCKERHUB_USERNAME }}/code-interpreter:latest -f - .

build-template:
name: Build E2B template
Expand All @@ -219,14 +219,22 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install E2B CLI
run: npm install -g @e2b/cli
- uses: actions/setup-python@v6
with:
python-version: '3.13'

- name: Build e2b
run: e2b template build
- name: Install development dependencies
working-directory: ./template
run: pip install -r requirements-dev.txt

- name: Build E2B template
id: build-template
working-directory: ./template
run: |
python build_prod.py
env:
E2B_ACCESS_TOKEN: ${{ secrets.E2B_ACCESS_TOKEN }}
E2B_API_KEY: ${{ secrets.E2B_API_KEY }}
E2B_DOMAIN: ${{ vars.E2B_DOMAIN }}

python-tests:
name: Python Tests
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
start-template-server:
docker run --rm -e E2B_LOCAL=true -p 49999:49999 -it $$(docker build . -q -f ./template/test.Dockerfile)
docker run --rm -e E2B_LOCAL=true -p 49999:49999 -it $$(python template/build_docker.py | docker build -q ./template -f -)

kill-template-server:
docker kill $(shell docker ps --filter expose=49999 --format {{.ID}})
74 changes: 0 additions & 74 deletions template/Dockerfile

This file was deleted.

74 changes: 43 additions & 31 deletions template/README.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,57 @@
# Using custom sandbox with Code Interpreter SDK

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).

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

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

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
1. Install E2B SDK

```
pip install e2b dotenv
```

2. Create a custom sandbox template:

**template.py**

```python
from e2b import Template

template = Template().from_template("code-interpreter-v1")
```

3. Create a build script:

```Dockerfile
FROM e2bdev/code-interpreter:latest
```
**build.py**

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

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

5. Use your custom sandbox with Code Interpreter SDK
Template.build(
template,
alias="code-interpreter-custom",
cpu_count=2,
memory_mb=2048,
on_build_logs=default_build_logger(),
)
```

**Python**
```python
from e2b_code_interpreter import Sandbox
sandbox = Sandbox.create(template="your-custom-sandbox-name")
execution = sandbox.run_code("print('hello')")
sandbox.kill()
3. Build the template:

# Or you can use `with` which handles closing the sandbox for you
with Sandbox.create(template="your-custom-sandbox-name") as sandbox:
execution = sandbox.run_code("print('hello')")
```

```
python build.py
```

**JavaScript/TypeScript**
4. Use the custom template:

```js
import {Sandbox} from '@e2b/code-interpreter'
```python
from e2b import Sandbox

const sandbox = await Sandbox.create({template: 'your-custom-sandbox-name'})
const execution = await sandbox.runCode('print("hello")')
await sandbox.kill()
```
sbx = Sandbox.create(template="code-interpreter-custom")
execution = sbx.run_code("print('Hello, World!')")
print(execution.logs.stdout)
```
11 changes: 11 additions & 0 deletions template/build_ci.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import os
from e2b import Template, default_build_logger
from template import make_template

Template.build(
make_template(set_user_workdir=True),
alias=os.environ["E2B_TESTS_TEMPLATE"],
cpu_count=2,
memory_mb=2048,
on_build_logs=default_build_logger(),
)
5 changes: 5 additions & 0 deletions template/build_docker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from template import make_template
from e2b import Template

tmp = make_template(kernels=["python", "javascript"])
print(Template.to_dockerfile(tmp))
13 changes: 13 additions & 0 deletions template/build_prod.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from dotenv import load_dotenv
from e2b import Template, default_build_logger
from template import make_template

load_dotenv()

Template.build(
make_template(set_user_workdir=True),
alias="code-interpreter-v1",
cpu_count=2,
memory_mb=2048,
on_build_logs=default_build_logger(),
)
13 changes: 13 additions & 0 deletions template/build_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from dotenv import load_dotenv
from e2b import Template, default_build_logger
from template import make_template

load_dotenv()

Template.build(
make_template(kernels=["python", "javascript"], set_user_workdir=True),
alias="code-interpreter-dev",
cpu_count=1,
memory_mb=1024,
on_build_logs=default_build_logger(min_level="debug"),
)
1 change: 0 additions & 1 deletion template/e2b.Dockerfile

This file was deleted.

18 changes: 0 additions & 18 deletions template/e2b.toml

This file was deleted.

2 changes: 2 additions & 0 deletions template/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
e2b==2.6.0
python-dotenv==1.2.1
6 changes: 3 additions & 3 deletions template/start-up.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ function start_jupyter_server() {
response=$(curl -s -o /dev/null -w "%{http_code}" "http://localhost:8888/api/status")
done

cd /root/.server/
/root/.server/.venv/bin/uvicorn main:app --host 0.0.0.0 --port 49999 --workers 1 --no-access-log --no-use-colors --timeout-keep-alive 640
cd /.server/
.venv/bin/uvicorn main:app --host 0.0.0.0 --port 49999 --workers 1 --no-access-log --no-use-colors --timeout-keep-alive 640
}

echo "Starting Code Interpreter server..."
start_jupyter_server &
MATPLOTLIBRC=/root/.config/matplotlib/.matplotlibrc jupyter server --IdentityProvider.token="" >/dev/null 2>&1
MATPLOTLIBRC=.config/matplotlib/.matplotlibrc jupyter server --IdentityProvider.token="" >/dev/null 2>&1
Loading