/Together-and-E2B

Materials for Together AI documentation and cookbook

Secure code execution with E2B

How to use the E2B Code Interpreter SDK with Together AI models.

How E2B Code Interpreter Works

Why give your AI app code interpreting capabilities?

E2B is the code execution layer for the AI app. The ability to execute the code as opposed to only generate it has many advantages:

  • Better reasoning
  • More complex tasks (e.g., advanced data analysis or mathematics)
  • Producing tangible results such as charts
  • Immediate testing (and correcting) of the produced output.

E2B as a secure choice for code execution

The open-source Code Interpreter SDK by E2B provides a long-running secure sandboxed environment where you can run the output generated by Together AI's LLMs. This SDK is tailor-made for AI data analysts, coding apps, and reasoning-heavy agents. The SDK quickly creates a secure cloud sandbox. Inside the sandbox is a running Jupyter server which the LLM can use.

Starting with Code Interpreter SDK

  1. Get your E2B API key here for free.

  2. Install the SDK

JavaScript & TypeScript version:

npm i @e2b/code-interpreter

Python version:

pip install e2b_code_interpreter
  1. Execute code with code interpreter inside sandbox

JavaScript & TypeScript version:

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

const sandbox = await CodeInterpreter.create()
await sandbox.notebook.execCell('x = 1')

const execution = await sandbox.notebook.execCell('x+=1; x')
console.log(execution.text)  // outputs 2

await sandbox.close()

Python version:

from e2b_code_interpreter import CodeInterpreter

with CodeInterpreter() as sandbox:
    sandbox.notebook.exec_cell("x = 1")

    execution = sandbox.notebook.exec_cell("x+=1; x")
    print(execution.text)  # outputs 2

More about E2B

E2B makes running AI-generated code in secure and isolated sandbox environments easy with the Code Interpreter SDK.

The SDK has a Python and JavaScript/TypeScript version. E2B works with any LLM and any AI frameworks (e.g., LangChain, LammaIndex, Vercel AI SDK, CrewAI, Autogen).

Check out the E2B docs and E2B Cookbook.