Overview
Code Interpreter runs code inside a sandbox and returns structured results. It is suitable for data analysis, notebook-style experiences, immediate execution of agent-generated code, and returning tables, text, errors, and file artifacts to a business system.
SDK entry points
Code Interpreter uses a dedicated SDK package:
import { Sandbox } from "@e2b/code-interpreter";In Python:
from e2b_code_interpreter import SandboxConnection parameters still use E2B_API_KEY, E2B_API_URL, and E2B_DOMAIN. FC Agent Sandbox provides the built-in Code Interpreter template code-interpreter-v1, and examples should specify that template explicitly.
Minimal example
import os
from e2b_code_interpreter import Sandbox
sandbox = Sandbox.create(
template="code-interpreter-v1",
api_key=os.environ["E2B_API_KEY"],
api_url=os.environ["E2B_API_URL"],
domain=os.environ["E2B_DOMAIN"],
)
try:
execution = sandbox.run_code("print('hello')")
print("".join(execution.logs.stdout or []).strip())
finally:
sandbox.kill()Core objects
sandbox.run_code()/sandbox.runCode(): run code and return the execution result.execution.logs.stdout/execution.logs.stderr: standard output and standard error.execution.text: the text result of the final bare expression.execution.results: a rich-result list that can include text, tables, and other structured results.execution.error: runtime errors, including error type, value, and traceback.Code Context: preserves variables, imports, and the working directory across multiple executions.