|
| 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.) |
0 commit comments