> ## 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.

# ModalSandbox integration

> Integrate with the ModalSandbox sandbox backend using LangChain Python.

[Modal](https://modal.com) provides serverless container infrastructure with GPU support. See the [Modal docs](https://modal.com/docs) for signup, authentication, and platform details.

## Installation

<CodeGroup>
  ```bash pip theme={null}
  pip install langchain-modal
  ```

  ```bash uv theme={null}
  uv add langchain-modal
  ```
</CodeGroup>

## Create a sandbox backend

In Python, you create the sandbox using the provider SDK, then wrap it with the [deepagents backend](/oss/python/deepagents/backends).

```python theme={null}
import modal

from langchain_modal import ModalSandbox

app = modal.App.lookup("your-app")
modal_sandbox = modal.Sandbox.create(app=app)
backend = ModalSandbox(sandbox=modal_sandbox)

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

## Use with Deep Agents

```python theme={null}
import modal
from langchain_anthropic import ChatAnthropic

from deepagents import create_deep_agent
from langchain_modal import ModalSandbox

app = modal.App.lookup("your-app")
modal_sandbox = modal.Sandbox.create(app=app)
backend = ModalSandbox(sandbox=modal_sandbox)

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

result = agent.invoke(
    {"messages": [{"role": "user", "content": "Install numpy and calculate pi"}]}
)
```

## Cleanup

You are responsible for managing the sandbox lifecycle via Modal.
When you are done, terminate the sandbox.

See also: [Sandboxes](/oss/python/deepagents/sandboxes).

***

<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/modal.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
  </Callout>
</div>
