Run LangChain Deep Agents in a PandaStack sandbox
Use langchain-pandastack as the sandbox for LangChain Deep Agents and Deep Agents Code, so the commands and file edits an agent makes run in a Firecracker microVM instead of on your machine.
Deep Agents is LangChain's agent harness for long, multi-step work: the agent plans, edits files and runs shell commands. Those commands have to run somewhere. With the langchain-pandastack package they run in a PandaStack sandbox, which is its own Firecracker microVM, so nothing the agent does touches your machine.
The package gives you two things:
PandaStackSandbox, a sandbox backend for the Deep Agents SDK.- a
pandastacksandbox provider for Deep Agents Code (dcode --sandbox pandastack).
Setup
pip install langchain-pandastack
export PANDASTACK_API_KEY=pds_...Create the API key in the dashboard. The package reads it from the environment.
Deep Agents SDK
Create a sandbox with the PandaStack SDK, wrap it, and pass it to the agent as its backend:
from deepagents import create_deep_agent
from langchain_anthropic import ChatAnthropic
from langchain_pandastack import PandaStackSandbox
from pandastack import Sandbox
sandbox = Sandbox.create(template="base", ttl_seconds=30 * 60)
backend = PandaStackSandbox(sandbox=sandbox)
agent = create_deep_agent(
model=ChatAnthropic(model="claude-sonnet-4-6"),
system_prompt="You are a Python coding assistant with sandbox access.",
backend=backend,
)
try:
result = agent.invoke(
{"messages": [{"role": "user", "content": "Write and run a hello world script."}]}
)
print(result["messages"][-1].content)
finally:
sandbox.kill()The agent's execute, read_file, write_file, edit_file, ls, grep and glob tools now all act inside the sandbox.
You can also call the backend yourself:
result = backend.execute("python3 --version")
print(result.output, result.exit_code)PandaStackSandbox does not create or delete sandboxes. You do that with the PandaStack SDK, so templates, snapshots and forks and the sandbox lifecycle work the same as anywhere else.
Deep Agents Code
Install the package into the dcode environment, then pick the provider:
dcode --install langchain-pandastack --package
export PANDASTACK_API_KEY=pds_...
dcode --sandbox pandastackdcode creates a sandbox when the session starts and deletes it when the session ends. To attach to a sandbox you already have:
dcode --sandbox pandastack --sandbox-id YOUR_SANDBOX_IDSettings
| Variable | Default | Meaning |
|---|---|---|
PANDASTACK_API_KEY | (required) | Your API key. Without it, the key saved by pandastack login is used. |
PANDASTACK_API | PandaStack cloud | API address, for a self-hosted PandaStack. |
PANDASTACK_TEMPLATE | base | Template for new sandboxes. |
PANDASTACK_SANDBOX_TTL | 1800 | Seconds of idle time after which PandaStack stops the sandbox. |
Each variable can also be set with a DEEPAGENTS_CODE_ prefix, for example DEEPAGENTS_CODE_PANDASTACK_API_KEY. The prefixed one wins.
Things to know
| Topic | Behavior |
|---|---|
| Working directory | Commands run in /workspace. Pass workdir= to change it. |
| Output | A command's stdout and stderr come back together, in the order the command wrote them. |
| Timeouts | A command gets 30 minutes by default. Pass timeout= to execute(), or timeout=0 for no limit. A command that hits its limit is stopped inside the sandbox and returns exit code 124 with the output it had produced. |
| Background processes | A command can start a server with & and return. The process keeps running in the sandbox and does not keep the call open. |
| Lost connection | If the connection drops before a command reports an exit code, execute() returns exit_code=None. The command may have finished or not, so check before running it again. |
| Idle sandboxes | PandaStack stops a sandbox after its idle time (ttl_seconds). The Deep Agents Code provider sets 30 minutes. |
| Custom templates | The sandbox needs base64 and mktemp for every command, timeout for time limits, and python3 for the file tools. PandaStack's own templates have all of them. |
Source
The package is open source under Apache-2.0: github.com/pandastack-io/langchain-pandastack. It is tested with LangChain's standard sandbox test suite against real PandaStack sandboxes.
Run code from a LangGraph agent
Give a LangGraph ReAct agent a self-hosted code interpreter in Python — a tool that runs inside a Firecracker microVM and hands back charts as objects, not stdout.
CrewAI code execution after CodeInterpreterTool
Build a CrewAI code execution sandbox tool with PandaStack after the built-in CodeInterpreterTool was deprecated and removed.