Skip to content

Commit 210c4fa

Browse files
Merge pull request #16 from VectorInstitute/e2b_template
Added option to override E2B template.
2 parents 1d829d8 + c147313 commit 210c4fa

File tree

3 files changed

+89
-1
lines changed

3 files changed

+89
-1
lines changed

e2b.Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM e2bdev/code-interpreter:latest
2+
3+
# All downloaded files will be available under /data
4+
WORKDIR /data
5+
6+
# # Example: download given link to publicly-shared Google Drive file and unzip.
7+
# # Set permission to open for the sandbox user.
8+
# RUN python3 -m pip install gdown && \
9+
# python3 -m gdown -O local_sqlite.zip "EXAMPLE_FILE_ID" && \
10+
# unzip local_sqlite.zip && \
11+
# chmod -R a+wr /data && \
12+
# rm -v local_sqlite.zip
13+
14+
# Example: download file from public URL- e.g., HuggingFace, or Github
15+
RUN wget --content-disposition \
16+
"https://huggingface.co/datasets/vector-institute/hotpotqa/resolve/main/data/validation-00000-of-00001.parquet"

e2b_template.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Custom E2B Template
2+
3+
The sandboxes are non-persistent. Each time your agent runs a command, all data files need to be uploaded again. If your data files are large (10MB total or more), it might take minutes before any command starts running. For performance reasons, you should consider bundling these data files into a custom E2B template. Here are the quick steps for setting that up.
4+
5+
Estimated time: 30 minutes.
6+
7+
## Prerequisites
8+
9+
Install Docker Engine ([Docker CE](https://docs.docker.com/engine/install/)).
10+
11+
Install Node Version Manager ([NVM](https://github.com/nvm-sh/nvm)).
12+
13+
Install the latest LTS Node version (22 as of 2025AUG03.)
14+
15+
Install the E2B utils and log into your account:
16+
17+
```bash
18+
npm i -g @e2b/cli
19+
e2b auth login
20+
```
21+
22+
## Steps
23+
24+
Modify `e2b.Dockerfile`. Replace the URL with the link to your data files.
25+
Important, try not to touch the `/home/user` folder, as that might create permission issues and break the Python installation.
26+
27+
28+
## Testing Locally
29+
30+
Try building the image locally.
31+
32+
```bash
33+
docker build . -f e2b.Dockerfile --tag e2b-example
34+
```
35+
36+
If the build works, run the following to enter the shell environment within the container. Make sure you can find your files under `/data`, as that is where your agent would access those data files.
37+
38+
```bash
39+
docker run -it --entrypoint /bin/bash e2b-example
40+
41+
# Within the container
42+
ls -lh /data
43+
44+
# You should see your data file listed.
45+
```
46+
47+
## Push to E2B
48+
49+
If the local tests looks reasonable, push the image to E2B as a template.
50+
51+
```bash
52+
# The command "/root/.jupyter/start-up.sh" is from the E2B base image
53+
# If you are only adding data files, you don't need to modify this line.
54+
55+
e2b template build -c "/root/.jupyter/start-up.sh"
56+
```
57+
58+
If the build is finished properly, you should see output like the following:
59+
60+
> ✅ Building sandbox template 9p6favrrqijhasgkq1tv finished.
61+
62+
## Modify your "System Prompt"
63+
64+
Previously, the agent assumes that all data files are under the initial working directory. That is not the case here. You should modify the system prompt and instruct the agent to look under `/data` (or whatever folder you specified in the Dockerfile.)

src/utils/tools/code_interpreter.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ def __init__(
108108
self,
109109
local_files: "Sequence[Path | str]| None" = None,
110110
timeout_seconds: int = 30,
111+
template_name: str | None = None,
111112
):
112113
"""Configure your Code Interpreter session.
113114
@@ -121,14 +122,19 @@ def __init__(
121122
to upload to sandbox working directory. Folders will be flattened.
122123
timeout_seconds : int
123124
Limit executions to this duration.
125+
template_name : str | None
126+
Optionally, override the default e2b template name.
127+
See e2b_template.md for details.
124128
"""
125129
self.timeout_seconds = timeout_seconds
126130
self.local_files = []
131+
self.template_name = template_name
127132

128133
# Recursively find files if the given path is a folder.
129134
if local_files:
130135
for _path in local_files:
131136
self.local_files.extend(_enumerate_files(_path))
137+
self.template_name = template_name
132138

133139
async def run_code(self, code: str) -> str:
134140
"""Run the given Python code in a sandbox environment.
@@ -138,7 +144,9 @@ async def run_code(self, code: str) -> str:
138144
code : str
139145
Python logic to execute.
140146
"""
141-
sbx = await AsyncSandbox.create(timeout=self.timeout_seconds)
147+
sbx = await AsyncSandbox.create(
148+
timeout=self.timeout_seconds, template=self.template_name
149+
)
142150
await _upload_files(sbx, self.local_files)
143151

144152
try:

0 commit comments

Comments
 (0)