Skip to main content
Deep Agents is LangChain’s agent harness for building LLM-powered agents, built on the LangGraph runtime. In Deep Agents, a sandbox backend defines the environment where the agent operates — E2B is a supported backend via the langchain-e2b package. With the E2B backend, the agent’s built-in tools all execute inside an isolated sandbox instead of your machine:
  • Filesystem toolsls, read_file, write_file, edit_file, glob, and grep operate on the sandbox filesystem.
  • Shell toolexecute runs arbitrary shell commands in the sandbox.

Install the dependencies

Set API keys for E2B and your model provider:
Then install the packages:

Basic example

Create an E2B sandbox, wrap it in the E2BSandbox 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.
The agent’s file operations and shell commands all run inside the sandbox — nothing touches your machine. Because the backend wraps the native E2B SDK sandbox, you can configure everything the SDK supports: custom templates, timeouts, persistence, or reconnecting to an existing sandbox by ID.

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:
Requires 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 from
  • E2B_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 same langchain-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

Templates

Build custom sandbox templates with pre-installed dependencies

Sandbox persistence

Auto-pause, resume, and manage sandbox lifecycle
https://mintcdn.com/e2b/Lrt1m5xlZDfdWijL/images/icons/open-swe.svg?fit=max&auto=format&n=Lrt1m5xlZDfdWijL&q=85&s=e221546326eea75ce94b3616ada2f724

Open SWE

LangChain’s coding agent framework with E2B built in