langchain-e2b package.
With the E2B backend, the agent’s built-in tools all execute inside an isolated sandbox instead of your machine:
- Filesystem tools —
ls,read_file,write_file,edit_file,glob, andgrepoperate on the sandbox filesystem. - Shell tool —
executeruns arbitrary shell commands in the sandbox.
Install the dependencies
Set API keys for E2B and your model provider:Basic example
Create an E2B sandbox, wrap it in theE2BSandbox backend, and pass it to create_deep_agent. You manage the sandbox lifecycle yourself — create it before the agent runs and kill it when you’re done.
Deep Agents Code (dcode)
Deep Agents Code is LangChain’s terminal coding agent built on Deep Agents.langchain-e2b ships a sandbox provider for it, so every dcode session can run in an E2B sandbox:
dcode >= 0.1.19 and langchain-e2b >= 0.0.4. Unlike the library path, dcode manages the sandbox lifecycle for you — it creates the sandbox on start and deletes it on exit. Configure it with:
E2B_TEMPLATE— custom sandbox template to start fromE2B_SANDBOX_TIMEOUT— sandbox timeout in seconds
Custom templates
By default, sandboxes start from the E2B base template. To pre-install languages, frameworks, or tools your agent needs — and cut setup time per run — build a custom template and pass it when creating the sandbox:Deep Agents vs. Open SWE
Open SWE is LangChain’s coding agent framework built on top of Deep Agents — both use the samelangchain-e2b backend under the hood, but they sit at different layers:
Use this page’s approach for custom agents; if you’re deploying a coding agent for your team, start from Open SWE instead.
Learn more
- Deep Agents sandboxes — sandbox backends overview
- E2B integration reference — LangChain’s E2B provider page
langchain-e2bon PyPI
Related guides
Templates
Build custom sandbox templates with pre-installed dependencies
Sandbox persistence
Auto-pause, resume, and manage sandbox lifecycle
Open SWE
LangChain’s coding agent framework with E2B built in