AI Code Execution SDK: Python & JS/TS libraries for integrating AI-generated code interpretation into applications.
# Model Context Protocol (MCP) - Powered by E2B
<!-- <p align="center">
<img width="100" src="https://raw.githubusercontent.com/e2b-dev/E2B/refs/heads/main/readme-assets/logo-circle.png" alt="e2b logo">
</p> -->


<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>
## Overview
This repository implements the Model Context Protocol (MCP) using [E2B](https://www.e2b.dev/), an open-source infrastructure for running AI-generated code in secure, isolated cloud sandboxes. MCP allows you to seamlessly integrate code execution within your AI workflows, providing a safe and reproducible environment for interacting with models. This allows models to access tools, perform calculations, and interact with external resources without compromising security or stability.
**Key Features:**
* **Secure Sandboxing:** Execute code generated by AI models in isolated environments, preventing malicious code from affecting your system.
* **Reproducibility:** Ensure consistent results by using pre-configured sandboxes with defined dependencies.
* **Scalability:** Leverage E2B's infrastructure to scale your code execution needs.
* **Language Support:** Supports both JavaScript/TypeScript and Python SDKs for interacting with sandboxes.
* **Model Context Integration:** Designed to seamlessly integrate with various LLMs and AI frameworks.
## Getting Started
Follow these steps to run your first sandbox and integrate it into your AI workflow:
### 1. Install the E2B SDK
Choose your preferred language and install the corresponding SDK:
**JavaScript / TypeScript:**
```bash
npm i @e2b/code-interpreter
Python:
pip install e2b-code-interpreter
E2B_API_KEY
environment variable:export E2B_API_KEY=e2b_***
(Replace e2b_***
with your actual API key.)The following examples demonstrate how to execute code within a secure sandbox using the E2B SDK.
JavaScript / TypeScript:
import { Sandbox } from '@e2b/code-interpreter';
async function main() {
const sbx = await Sandbox.create();
await sbx.runCode('x = 1');
const execution = await sbx.runCode('x+=1; x');
console.log(execution.text); // Outputs: 2
await sbx.close(); // Remember to close the sandbox when you're done!
}
main();
Python:
from e2b_code_interpreter import Sandbox
with Sandbox() as sandbox:
sandbox.run_code("x = 1")
execution = sandbox.run_code("x+=1; x")
print(execution.text) # Outputs: 2
Explanation:
run_code
method executes the provided code snippet within the sandbox.execution.text
attribute contains the output of the executed code.sbx.close()
is used to properly terminate the sandbox and release resources. It's important to close sandboxes when they are no longer needed.For comprehensive information on the E2B SDK and its features, visit the E2B documentation.
Get inspired by real-world examples and integrations with different LLMs and AI frameworks in our Cookbook. This cookbook provides practical demonstrations of how to leverage E2B for various AI-powered applications.
We welcome contributions to this project! Please refer to the contributing guidelines for more information.
This project is licensed under the [License Name] License.
```
e2b-dev/code-interpreter
March 11, 2024
July 7, 2025
MDX