Repository

code-interpreter

Python & JS/TS SDK for running AI-generated code/code interpreting in your AI app

README

E2B Code Interpreter Preview
E2B Code Interpreter Preview

<h4 align="center">
<a href="https://pypi.org/project/e2b/">
<img alt="Last 1 month downloads for the Python SDK" loading="lazy" width="200" height="20" decoding="async" data-nimg="1"
style="color:transparent;width:auto;height:100%" src="https://img.shields.io/pypi/dm/e2b?label=PyPI%20Downloads">
</a>
<a href="https://www.npmjs.com/package/e2b">
<img alt="Last 1 month downloads for the JavaScript SDK" loading="lazy" width="200" height="20" decoding="async" data-nimg="1"
style="color:transparent;width:auto;height:100%" src="https://img.shields.io/npm/dm/e2b?label=NPM%20Downloads">
</a>
</h4>

[!NOTE]
The @e2b/code-interpreter and e2b-code-interpreter SDK sources now live in the E2B monorepo, under packages/code-interpreter-js and packages/code-interpreter-python. Open SDK issues and pull requests there. This repository keeps the sandbox template and the chart data extractor.

What is E2B?

E2B is an open-source infrastructure that allows you to run AI-generated code in secure isolated sandboxes in the cloud. To start and control sandboxes, use our JavaScript SDK or Python SDK.

Run your first Sandbox

1. Install SDK

JavaScript / TypeScript

npm i @e2b/code-interpreter

Python

pip install e2b-code-interpreter

2. Get your E2B API key

  1. Sign up to E2B here.
  2. Get your API key here.
  3. Set environment variable with your API key.
    E2B_API_KEY=e2b_***

3. Execute code with code interpreter inside Sandbox

JavaScript / TypeScript

import { Sandbox } from '@e2b/code-interpreter'

const sbx = await Sandbox.create()
await sbx.runCode('x = 1')

const execution = await sbx.runCode('x+=1; x')
console.log(execution.text)  // outputs 2

Python

from e2b_code_interpreter import Sandbox

with Sandbox.create() as sandbox:
    sandbox.run_code("x = 1")
    execution = sandbox.run_code("x+=1; x")
    print(execution.text)  # outputs 2

4. Check docs

Visit E2B documentation.

5. E2B cookbook

Visit our Cookbook to get inspired by examples with different LLMs and AI frameworks.

Customizing the sandbox template

Need extra packages or a different runtime? You can build your own Code Interpreter sandbox template. See the template guide for a step-by-step walkthrough of creating, building, and using a custom template (as well as building the production code-interpreter-v1 template).

What is E2B?

3

1. Install SDK

1

  • JavaScript / TypeScript

2. Get your E2B API key

2

3. Execute code with code interpreter inside Sandbox

1

  • JavaScript / TypeScript

4. Check docs

1

5. E2B cookbook

1

Customizing the sandbox template

1