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.
-
Create custom sandbox by following this guide
-
Use prebuilt E2B Code Interpreter image by replacing the
FROMcommand in youre2b.Dockerfilewith followingFROM e2bdev/code-interpreter:latest -
Copy
start-up.shto the same directory where's youre2b.toml -
Run the following in the same directory where's your
e2b.tomle2b template build -c "/root/.jupyter/start-up.sh" -
Use your custom sandbox with Code Interpreter SDK
Python
from e2b_code_interpreter import Sandbox sandbox = Sandbox(template="your-custom-sandbox-name") execution = sandbox.run_code("print('hello')") sandbox.kill() # Or you can use `with` which handles closing the sandbox for you with Sandbox(template="your-custom-sandbox-name") as sandbox: execution = sandbox.run_code("print('hello')")
JavaScript/TypeScript
import {Sandbox} from '@e2b/code-interpreter'
const sandbox = await Sandbox.create({template: 'your-custom-sandbox-name'}) const execution = await sandbox.runCode('print("hello")') await sandbox.kill()