Skip to main content
LangSmith sandboxes are sandbox environments that LangChain manages for you, so there is no separate provider account, billing, or infrastructure to set up. They are the zero-setup default for running agent code, while third-party providers such as Daytona and Modal remain available when you want to bring your own. Because they are part of the LangChain platform, you manage them alongside your other LangSmith resources. For setup, snapshots, service URLs, and the auth proxy, see the LangSmith Sandboxes docs.

Installation

pip install "langsmith[sandbox]" deepagents

Set your API key

export LANGSMITH_API_KEY="<your-api-key>"
SandboxClient() reads this key from the environment, so no further configuration is required.

Create a sandbox backend

Create a LangSmith sandbox with SandboxClient, then wrap it in LangSmithSandbox to run it as a Deep Agents backend.
from deepagents.backends.langsmith import LangSmithSandbox
from langsmith.sandbox import SandboxClient

client = SandboxClient()
ls_sandbox = client.create_sandbox()
backend = LangSmithSandbox(sandbox=ls_sandbox)

result = backend.execute("echo hello")
print(result.output)

# Delete the sandbox when you are done (see Clean up)
client.delete_sandbox(ls_sandbox.name)

Use with Deep Agents

Pass the backend to create_deep_agent along with a chat model such as ChatAnthropic, then invoke the agent. The try/finally block deletes the sandbox when the try block finishes or an error occurs.
from deepagents import create_deep_agent
from deepagents.backends.langsmith import LangSmithSandbox
from langchain_anthropic import ChatAnthropic
from langsmith.sandbox import SandboxClient

client = SandboxClient()
ls_sandbox = client.create_sandbox()
backend = LangSmithSandbox(sandbox=ls_sandbox)

agent = create_deep_agent(
    model=ChatAnthropic(model="claude-sonnet-4-6"),
    system_prompt="You are a coding assistant with sandbox access.",
    backend=backend,
)

try:
    result = agent.invoke(
        {
            "messages": [
                {"role": "user", "content": "Create a hello world Python script and run it"}
            ]
        }
    )
    print(result["messages"][-1].content_blocks)
finally:
    client.delete_sandbox(ls_sandbox.name)

Clean up

Delete sandboxes when you are done, since they consume resources until deleted.
client.delete_sandbox(ls_sandbox.name)
You can also manage sandbox resources from the LangSmith UI under Sandboxes. For more detail, see: