# code-interpreter

> MCP Client

AI Code Execution SDK: Python & JS/TS libraries for integrating AI-generated code interpretation into applications.

## Overview

- **Category:** AI
- **Language:** MDX
- **Stars:** 2369
- **Forks:** 159
- **Owner:** e2b-dev
- **GitHub:** https://github.com/e2b-dev/code-interpreter
- **Homepage:** https://e2b.dev
- **Created:** 2024-03-11T22:08:25+00:00
- **Updated:** 2025-07-07T14:58:37+00:00
- **Source:** https://model-context-protocol.com/clients/code-interpreter

## Setup

## Setup

To start using E2B, follow these steps:

### Prerequisites

*   **JavaScript/TypeScript:** Node.js and npm (Node Package Manager) or yarn.
*   **Python:** Python 3.7 or higher and pip (Python Package Installer).

### 1. Install the E2B SDK

Choose the SDK based on your preferred language:

**JavaScript / TypeScript:**

```bash
npm install @e2b/code-interpreter
```

or, if you prefer yarn:

```bash
yarn add @e2b/code-interpreter
```

**Python:**

```bash
pip install e2b-code-interpreter
```

### 2. Obtain and Configure your E2B API Key

1.  **Sign up:** Create an E2B account at [https://e2b.dev](https://e2b.dev).
2.  **Get your API Key:**  Find your API key in the E2B dashboard under the "Keys" tab: [https://e2b.dev/dashboard?tab=keys](https://e2b.dev/dashboard?tab=keys).
3.  **Set the Environment Variable:**  Set the `E2B_API_KEY` environment variable with your API key. This allows the SDK to authenticate with the E2B service.

    **Example (Linux/macOS):**

    ```bash
    export E2B_API_KEY="e2b_YOUR_API_KEY"
    ```

    **Example (Windows):**

    ```bash
    set E2B_API_KEY=e2b_YOUR_API_KEY
    ```

    Replace `e2b_YOUR_API_KEY` with your actual API key.  Make sure to set this environment variable before running your code.  Consider adding this to your shell's configuration file (e.g., `.bashrc`, `.zshrc`, `.bash_profile`) for persistence.

## Tools

## Available Tools

E2B provides the following tools and features for running AI-generated code in secure, isolated cloud sandboxes:

*   **JavaScript/TypeScript SDK:** Allows you to start and control sandboxes from JavaScript or TypeScript environments.
    *   Installation: `npm i @e2b/code-interpreter`
    *   Usage Example:
        ```ts
        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)
        ```

*   **Python SDK:** Enables starting and controlling sandboxes from Python environments.
    *   Installation: `pip install e2b-code-interpreter`
    *   Usage Example:
        ```py
        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)
        ```

*   **Secure Isolated Sandboxes:** Provides a secure environment for executing AI-generated code, preventing potential security risks.

*   **Code Execution:** Allows you to execute arbitrary code within the sandbox environment.
    *   Usage: The `runCode` function in both SDKs executes code within the sandbox.

*   **API Key Authentication:** Secures access to E2B services using API keys.  You can obtain an API key after signing up on the E2B platform.

*   **E2B Cookbook:** Offers a collection of examples and use cases demonstrating how to use E2B with various LLMs and AI frameworks.
