An Introduction to the Code-Interpreter Project
What is E2B?
E2B is an open-source platform designed to run AI-generated code in secure, isolated environments known as sandboxes. These sandboxes are hosted in the cloud, ensuring both security and convenience for developers. The platform can be interacted with using the E2B JavaScript SDK or Python SDK, providing flexibility for developers who prefer either language.
Running Your First Sandbox
Getting started with E2B and running your first sandbox involves a few straightforward steps:
1. Install the SDK
For developers using JavaScript or TypeScript, the SDK can be installed via npm:
npm i @e2b/code-interpreter
For those using Python, the package installation is done with pip:
pip install e2b-code-interpreter
2. Obtain Your E2B API Key
Before you can begin, you'll need to acquire an API key. Here’s how to do it:
- Sign up for an E2B account by visiting their website.
- Once registered, navigate to your dashboard to retrieve your API key.
- Store this key in your environment variables:
E2B_API_KEY=e2b_***
3. Execute Code Within a Sandbox
With the setup complete, you can now execute code using the sandbox feature:
For JavaScript or TypeScript, the process is as follows:
import { Sandbox } from '@e2b/code-interpreter'
const sandbox = await Sandbox.create()
await sbx.runCode('x = 1')
const execution = await sbx.runCode('x+=1; x')
console.log(execution.text) // outputs 2
In Python, the code execution would look like this:
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
4. Explore the Documentation
To learn more about the capabilities and features of E2B, check out their extensive documentation available here.
5. Get Inspired with the E2B Cookbook
For those seeking practical examples and projects, the E2B Cookbook is a valuable resource. It offers a collection of examples using various Large Language Models (LLMs) and AI frameworks, providing a great source of ideas and inspiration. Explore the E2B Cookbook here.
In summary, E2B provides developers with a powerful tool for executing AI-generated code securely in the cloud. With a user-friendly setup process and comprehensive documentation, it opens up exciting possibilities for innovation in AI development.