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.
- Install E2B SDK
pip install e2b dotenv
- Create a custom sandbox template:
template.py
from e2b import Template
template = Template().from_template("code-interpreter-v1")- Create a build script:
build.py
from dotenv import load_dotenv
from .template import template
from e2b import Template, default_build_logger
load_dotenv()
Template.build(
template,
alias="code-interpreter-custom",
cpu_count=2,
memory_mb=2048,
on_build_logs=default_build_logger(),
)- Build the template:
python build.py
- Use the custom template:
from e2b import Sandbox
sbx = Sandbox.create(template="code-interpreter-custom")
execution = sbx.run_code("print('Hello, World!')")
print(execution.logs.stdout)