Customize the template
Extend the Code Interpreter sandbox or build the production template from source
The Code Interpreter SDK runs on the public code-interpreter-v1 sandbox template. You can customize it in two ways:
- Create a custom template that extends
code-interpreter-v1with extra packages or a different runtime — this is the recommended approach for most use cases. - Build the production template directly from the
code-interpreterrepository — useful when contributing to the SDK or building the officialcode-interpreter-v1template yourself.
Create a custom template
Use this when you need extra preinstalled packages or a different runtime. Your template builds on top of code-interpreter-v1, so everything the Code Interpreter SDK relies on stays in place.
1. Install the E2B SDK
npm install e2b dotenv2. Create a template file
// template.ts
import { Template } from 'e2b';
export const template = Template().fromTemplate("code-interpreter-v1");3. Create a build script
// build.ts
import "dotenv/config";
import { Template, defaultBuildLogger } from 'e2b';
import { template } from './template';
async function main() {
await Template.build(template, 'code-interpreter-custom', {
cpuCount: 2,
memoryMB: 2048,
onBuildLogs: defaultBuildLogger(),
});
}
main().catch(console.error);4. Set your environment variables
Create a .env file with your API key (loaded by dotenv / load_dotenv()):
E2B_API_KEY=e2b_***5. Build the template
npx tsx build.ts6. Use the custom template
import { Sandbox } from '@e2b/code-interpreter'
const sbx = await Sandbox.create("code-interpreter-custom")
const execution = await sbx.runCode("print('Hello, World!')")
console.log(execution.logs.stdout)See Install custom packages for preinstalling specific Python and Node.js packages with pip / npm.
Build the production template
To build the official code-interpreter-v1 template from the code-interpreter repository, use build_prod.py. This is the script CI and releases run, and it’s the path to take when you’re contributing to the SDK or want to rebuild the production template yourself.
1. Clone the repository
The template lives in the template/ directory — run the remaining steps from there.
git clone https://github.com/e2b-dev/code-interpreter.git
cd code-interpreter/template2. Install the build dependencies
pip install -r requirements-dev.txt3. Provide your credentials
Create a .env file with your API key:
E2B_API_KEY=e2b_***4. Build the template
python build_prod.pyTo force a clean rebuild that ignores the layer cache, set SKIP_CACHE=true:
SKIP_CACHE=true python build_prod.py