LangChain Deep Agents
Let a LangChain deep agent run its shell commands and file tools in a WBX sandbox – an isolated Linux microVM – instead of on your own machine. The langchain-wbxsandbox package is the backend; WBX Sandbox is listed among the sandbox integrations in the LangChain docs.
Install
pip install langchain-wbxsandbox langchain-anthropic export WBXSANDBOX_API_KEY=YOUR_API_KEY # API keys in the portal export ANTHROPIC_API_KEY=… # for the model below
Python 3.11 or newer. The package installs deepagents and the Python SDK. WBXSANDBOX_URL is optional (default https://sandbox.wbx.cz). Any LangChain chat model works – install its provider package instead of langchain-anthropic.
Use it with a deep agent
from deepagents import create_deep_agent from langchain_wbxsandbox import WBXSandbox # a sandbox from the "base" template; destroyed when the block ends with WBXSandbox.create(template="base", lifetime=1800) as sandbox: agent = create_deep_agent( model="anthropic:claude-sonnet-5-5", # replace with a current model system_prompt="You are a coding assistant. Use the sandbox to run code.", backend=sandbox, ) result = agent.invoke({"messages": [{"role": "user", "content": "Write fib.py that prints the first 10 Fibonacci numbers and run it."}]}) print(result["messages"][-1].content)
The agent gets the execute tool and the file tools ls, read_file, write_file, edit_file, glob and grep – all running inside the sandbox, as root, with pip, npm and apt available.
Create, reconnect, destroy
from langchain_wbxsandbox import WBXSandbox
sandbox = WBXSandbox.create(template="base", lifetime=3600, timeout=600,
internet=False) # other options go to Sandbox.create()
r = sandbox.execute("python3 --version")
print(r.exit_code, r.output)
same = WBXSandbox.connect(sandbox.id) # later, e.g. in the next turn
sandbox.kill() # destroy it with its disk
| Call | Default | Meaning |
|---|---|---|
WBXSandbox.create(template=…) | "base" | Template – see Templates. |
lifetime | 1800 s | Seconds until the sandbox is destroyed (your plan sets the maximum). |
timeout | 1800 s | Default limit for one command; 0 = no limit. A command over the limit is stopped and reported with exit code 124. |
url, api_key | from the environment | WBXSANDBOX_URL / WBXSANDBOX_API_KEY. |
**kwargs | – | Passed to wbxsandbox.Sandbox.create(): env, metadata, internet, allow, block, compute_class, ip, name, on_timeout… |
WBXSandbox(sandbox=sb, timeout=…) | – | Wrap a sandbox you created with the Python SDK. |
.sandbox | – | The underlying wbxsandbox.Sandbox – public URLs, lifetime, sleep and resume. |
Good to know
execute()runs the command with/bin/sh -c; the output is stdout followed by stderr, with the stderr part wrapped instderrtags.- Uploads create missing directories. Relative paths are refused (
invalid_path); file errors are reported asfile_not_found,is_directoryorpermission_denied. - By default the sandbox is destroyed when its lifetime ends. To keep the agent's files between runs, create it with
name="my-project", on_timeout="pause"– it then falls asleep instead, and the same name reuses it. - The package works with
wbxsandbox0.15, so snapshots and clones are not available through it yet – see Versions.
Source and issues: github.com/WBX-Sandbox/langchain-wbxsandbox · package: pypi.org/project/langchain-wbxsandbox.