Documentation
E2B + Groq: Open-Source Code Interpreter
E2B Code Interpreter is an open-source SDK that provides secure, sandboxed environments for executing code generated by LLMs via Groq API. Built specifically for AI data analysts, coding applications, and reasoning-heavy agents, E2B enables you to both generate and execute code in a secure sandbox environment in real-time.
Python Quick Start (3 minutes to hello world)
1. Install the required packages:
pip install groq e2b-code-interpreter python-dotenv
2. Configure your Groq and E2B API keys:
export GROQ_API_KEY="your-groq-api-key"
export E2B_API_KEY="your-e2b-api-key"
3. Create your first simple and fast Code Interpreter application that generates and executes code to analyze data:
Running the below code will create a secure sandbox environment, generate Python code using llama-3.3-70b-versatile
powered by Groq, execute the code, and display the results. When you go to your
E2B Dashboard, you'll see your sandbox's data.
from e2b_code_interpreter import Sandbox
from groq import Groq
import os
e2b_api_key = os.environ.get('E2B_API_KEY')
groq_api_key = os.environ.get('GROQ_API_KEY')
# Initialize Groq client
client = Groq(api_key=groq_api_key)
SYSTEM_PROMPT = """You are a Python data scientist. Generate simple code that:
1. Uses numpy to generate 5 random numbers
2. Prints only the mean and standard deviation in a clean format
Example output format:
Mean: 5.2
Std Dev: 1.8"""
def main():
# Create sandbox instance (by default, sandbox instances stay alive for 5 mins)
sbx = Sandbox()
# Get code from Groq
response = client.chat.completions.create(
model="llama-3.1-70b-versatile",
messages=[
{"role": "system", "content": SYSTEM_PROMPT},
{"role": "user", "content": "Generate random numbers and show their mean and standard deviation"}
]
)
# Extract and run the code
code = response.choices[0].message.content
if "```python" in code:
code = code.split("```python")[1].split("```")[0]
print("\nGenerated Python code:")
print(code)
print("\nExecuting code in sandbox...")
execution = sbx.run_code(code)
print(execution.logs.stdout[0])
if __name__ == "__main__":
main()
Challenge: Try modifying the example to analyze your own dataset or solve a different data science problem!
For more detailed documentation and resources on building with E2B and Groq, see: