LangGraph
Give your LangGraph graph a code-execution tool backed by E2B. Model-written Python runs in an isolated sandbox that survives graph steps, checkpoints and interrupts.
- E2B
- Sandbox as a graph tool
- e2b-code-interpreter
- Python
Get started
Paste the prompt into your coding agent, or follow the steps yourself.
Paste this into your coding agent
Add E2B sandboxes to this LangGraph project.
- 1.Install e2b-code-interpreter using the project's package manager.
- 2.The SDK needs the E2B_API_KEY environment variable. If it isn't set, ask me for my API key from https://console.e2b.dev/?tab=keys. Never hardcode it.
- 3.Follow the LangGraph guide at https://docs.e2b.dev/agents/langgraph. Add a run_python tool that reads the Sandbox from runtime context, keep the sandbox_id in graph state, reconnect with Sandbox.connect() on resume, and kill the sandbox in a finally block.
- 4.Run the graph once and show me the output that came from the sandbox.
Or set it up yourself
1. Install the dependencies
2. Set your API keys
3. Add a code-execution tool
4. Run with one sandbox per run
What runs in the sandbox
Code the model writes runs in an isolated sandbox, away from the machine running your graph.
- Python the model writes, run in a Jupyter kernel with run_code. Output and errors flow back into graph state.
- One sandbox per run: files and variables carry over between nodes. Keep its sandbox_id in state and Sandbox.connect() after an interrupt.
- The default timeout is 300 seconds. on_timeout pause with auto_resume keeps the sandbox through long human reviews.
- Host API keys stay with your graph unless the task needs them. Kill the sandbox in a finally block.
More agent frameworks
Other frameworks that run their tools on E2B.
