PandaStack
Agents

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 pandastack sandbox 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 pandastack

dcode 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_ID

Settings

VariableDefaultMeaning
PANDASTACK_API_KEY(required)Your API key. Without it, the key saved by pandastack login is used.
PANDASTACK_APIPandaStack cloudAPI address, for a self-hosted PandaStack.
PANDASTACK_TEMPLATEbaseTemplate for new sandboxes.
PANDASTACK_SANDBOX_TTL1800Seconds 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

TopicBehavior
Working directoryCommands run in /workspace. Pass workdir= to change it.
OutputA command's stdout and stderr come back together, in the order the command wrote them.
TimeoutsA 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 processesA command can start a server with & and return. The process keeps running in the sandbox and does not keep the call open.
Lost connectionIf 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 sandboxesPandaStack stops a sandbox after its idle time (ttl_seconds). The Deep Agents Code provider sets 30 minutes.
Custom templatesThe 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.

On this page