> ## Documentation Index
> Fetch the complete documentation index at: https://langchain-5e9cc07a-preview-opensw-1782332329-96d87c7.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# LangSmith sandbox integration

> Integrate with the LangSmithSandbox type using LangChain Python.

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 AgentCore, Daytona, E2B, Modal, Runloop, and Vercel 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](/langsmith/sandboxes).

## Installation

<CodeGroup>
  ```bash pip theme={null}
  pip install "langsmith[sandbox]" deepagents
  ```

  ```bash uv theme={null}
  uv add "langsmith[sandbox]" deepagents
  ```
</CodeGroup>

## Set your API key

```bash theme={null}
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](https://reference.langchain.com/python/deepagents/backends/langsmith/LangSmithSandbox) to run it as a [Deep Agents backend](/oss/python/deepagents/backends).

```python theme={null}
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](https://reference.langchain.com/python/deepagents/graph/create_deep_agent) along with a chat model such as [ChatAnthropic](https://reference.langchain.com/python/langchain-anthropic/chat_models/ChatAnthropic), then invoke the agent. The `try`/`finally` block deletes the sandbox when the try block finishes or an error occurs.

```python theme={null}
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.

```python theme={null}
client.delete_sandbox(ls_sandbox.name)
```

You can also manage sandbox resources from the [LangSmith UI](https://smith.langchain.com?utm_source=docs\&utm_medium=cta\&utm_campaign=langsmith-signup\&utm_content=oss-python-integrations-sandboxes-langsmith) under **Sandboxes**.

For more detail, see:

* [Sandboxes in Deep Agents](/oss/python/deepagents/sandboxes): lifecycle, scoping, and a comparison of sandbox providers.
* [LangSmith Sandboxes](/langsmith/sandboxes): snapshots, service URLs, the auth proxy, and the SDK reference.

***

<div className="source-links">
  <Callout icon="terminal-2">
    [Connect these docs](/use-these-docs) to Claude, VSCode, and more via MCP for real-time answers.
  </Callout>

  <Callout icon="edit">
    [Edit this page on GitHub](https://github.com/langchain-ai/docs/edit/main/src/oss/python/integrations/sandboxes/langsmith.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
  </Callout>
</div>
