# E2B

> Run AI-generated code in secure, isolated cloud sandboxes

- Category: Agents & Automation / Code Sandboxes & Isolation
- Language: Python
- Licence: Apache-2.0
- Repository: https://github.com/e2b-dev/E2B
- Website: https://e2b.dev/docs
- Canonical page: https://ai-tldr.dev/tools/e2b/

## In short

E2B is open-source infrastructure that lets you run AI-generated code in secure, isolated sandboxes in the cloud. Each sandbox is a separate environment, so code produced by a language model can run safely without putting your own systems at risk. It sits in the Code Sandboxes & Isolation category of the Agents & Automation tools and is open-source, written in Python and licensed Apache-2.0.

## Overview

E2B is open-source infrastructure that lets you run AI-generated code in secure, isolated sandboxes in the cloud. Each sandbox is a separate environment, so code produced by a language model can run safely without putting your own systems at risk.

You start and control sandboxes from your own application using the E2B JavaScript or Python SDK. Inside a sandbox you can run shell commands and, with the Code Interpreter SDK, execute code directly and read back the result. E2B can be used as a hosted service with an API key, or self-hosted on your own cloud.

## What it does

- Secure, isolated cloud sandboxes for running untrusted, AI-generated code
- Official SDKs for both JavaScript/TypeScript and Python
- Run shell commands inside a sandbox and read back stdout
- Code Interpreter SDK to execute code with runCode() / run_code() and get the result
- Self-hosting option using Terraform on AWS or Google Cloud (GCP)
- Cookbook with examples for different LLMs and AI frameworks

## Getting started

Install the SDK, set your E2B API key, then create a sandbox and run commands inside it. For executing code and reading the result, add the Code Interpreter SDK.

1. Install the SDK

   Install the E2B SDK for your language using npm or pip.

```bash
npm i e2b        # JavaScript / TypeScript
pip install e2b  # Python
```

2. Get and set your API key

   Sign up at e2b.dev, grab your API key from the dashboard, and set it as an environment variable.

```bash
E2B_API_KEY=e2b_***
```

3. Start a sandbox and run a command

   Create a sandbox and run a shell command inside it, then read the output.

```ts
import Sandbox from 'e2b'

const sandbox = await Sandbox.create()
const result = await sandbox.commands.run('echo "Hello from E2B!"')
console.log(result.stdout) // Hello from E2B!
```

4. Execute code with the Code Interpreter SDK

   To run code and read back the result, install the Code Interpreter SDK and use runCode() / run_code().

```bash
npm i @e2b/code-interpreter     # JavaScript/TypeScript
pip install e2b-code-interpreter  # Python
```

## When to use it

- Safely running code that a language model generates, without exposing your own machine
- Building AI agents and code interpreters that need to execute and check code on the fly
- Giving data-analysis or coding assistants a clean, throwaway environment for each task
- Self-hosting sandbox infrastructure on AWS or GCP for full control over where code runs
