Skip to main content
The LangChain logo inside the boxd card. LangChain builds open-source frameworks for AI agents. Deep Agents is its agent harness: an agent that plans, runs shell commands, and edits files in a sandbox you choose. BoxdSandbox makes that sandbox a boxd machine. It comes from boxd-langchain, a package the boxd team maintains, and LangChain lists it with its sandbox integrations (pull request). Deep Agents compiles to a LangGraph graph, so the same backend works from LangChain, LangGraph, and Deep Agents.

Set up

1

Install the package

langchain-anthropic is for the example below; use your model provider’s package instead.
2

Create an API key

Machines are created and billed in the key’s organization.
3

Give the agent a machine

Set ANTHROPIC_API_KEY for the model. The agent’s shell and file tools now run on the machine, and leaving the with block deletes it.

Come back to a machine

To keep the agent’s work, create the machine yourself and hand its id to BoxdSandbox. A backend made from an existing machine never deletes it.
A hibernated machine keeps its disk and memory, and you stop paying for CPU and memory. Store the machine’s id. The next command wakes the machine, with its files as the agent left them:

Fork a machine

A fork copies a machine into a new one, with its files and running processes as they are at that moment. Set a project up once, fork it, and give each agent its own copy:
The two machines change independently after the fork. backend.client is the plain boxd Python SDK client, so snapshots, egress allowlists, and everything else boxd offers are one call away. The package’s parallel_forks.py example runs two agents on two forks at once.

Deep Agents Code

The package also registers boxd as a sandbox for Deep Agents Code, LangChain’s terminal coding agent:
Each session gets its own machine. dcode deletes it on a clean exit, and BOXD_DELETE_AFTER has boxd delete it after that many seconds if a run ends early. To pick a machine up again, pass its id or name, and dcode wakes it if it is asleep:

What each machine gets

  • Isolation when you ask for it: isolated=True creates the machine with no boxd credentials and no route to your organization’s other machines. Use it whenever a model writes the code that runs.
  • A deadline: delete_after sets a delete-after timer, so boxd deletes the machine even if your process dies before the with block ends.
  • The default image: Ubuntu 24.04 with Python 3, git, Node.js, Docker, and ripgrep. For your own dependencies, start from a snapshot with BoxdSandbox.create(from_snapshot="my-snapshot").
  • Commands as the boxd user, who has passwordless sudo, in /home/boxd. A command’s output is its stdout and stderr, and its exit code comes back unchanged.
  • A timeout: a command that runs past its timeout, 30 minutes by default, is stopped with its whole process group and returns exit code 124.

Read more