Skip to main content
E2B provides cloud sandboxes for running AI-generated code in isolated environments. See the E2B docs for signup, authentication, and platform details.

Installation

Authentication

Set your E2B API key:
Configure E2B-specific options, such as templates or sandbox lifetime, through the E2B SDK when creating the sandbox.

Create a sandbox

In Python, you create the sandbox using the E2B SDK, then wrap it with the deepagents backend.

Use with Deep Agents

Use with Deep Agents Code

langchain-e2b also publishes an E2B sandbox provider for Deep Agents Code, so dcode can run agent tool calls inside an E2B sandbox. Install the package into the dcode environment, set your API key, then select the provider:
Using E2B with Deep Agents Code requires dcode 0.1.19 or newer and langchain-e2b 0.0.4 or newer.
E2B sandboxes use /home/user as the default working directory. To create sandboxes from a specific E2B template, set E2B_TEMPLATE; to change the sandbox lifetime, set E2B_SANDBOX_TIMEOUT (in seconds). Each variable also accepts a DEEPAGENTS_CODE_-prefixed form (for example, DEEPAGENTS_CODE_E2B_API_KEY), which takes precedence. Deep Agents Code manages the sandbox lifecycle for you, creating a sandbox on start and deleting it on exit.

Cleanup

Always kill E2B sandboxes when you are done to avoid ongoing resource usage. See also: Sandboxes.