Metadata-Version: 2.4
Name: gatana-langchain
Version: 1.0.1
Summary: A toolkit for building LangChain applications
Project-URL: Homepage, https://github.com/gatana-ai/gatana-langchain-sandbox
Project-URL: Repository, https://github.com/gatana-ai/gatana-langchain-sandbox
Project-URL: Issues, https://github.com/gatana-ai/gatana-langchain-sandbox/issues
Project-URL: Changelog, https://github.com/gatana-ai/gatana-langchain-sandbox/blob/main/CHANGELOG.md
Author-email: Gatana <engineering@gatana.ai>
License-Expression: MIT
Keywords: agents,ai,gatana,langchain,llm
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Typing :: Typed
Requires-Python: >=3.11
Requires-Dist: deepagents>=0.4
Requires-Dist: gatana-client>=0.1.0
Requires-Dist: langchain-core>=0.3
Description-Content-Type: text/markdown

# gatana-langchain

Current version: **v1.0.1**

[![PyPI](https://img.shields.io/pypi/v/gatana-langchain)](https://pypi.org/project/gatana-langchain/)
[![Python](https://img.shields.io/pypi/pyversions/gatana-langchain)](https://pypi.org/project/gatana-langchain/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

A [LangChain sandbox backend](https://docs.langchain.com/oss/python/deepagents/sandboxes) for [Gatana](https://www.gatana.ai). Use Gatana sandboxes as isolated execution environments for LangChain [deep agents](https://docs.langchain.com/oss/python/deepagents/harness).

## Features

- Drop-in sandbox backend for LangChain's `deepagents` framework
- Isolated command execution, file upload/download, and full filesystem tool support
- Auto-creates and cleans up sandboxes via context manager
- Fully typed with [PEP 561](https://peps.python.org/pep-0561/) support
- Python 3.11+

## Installation

```bash
pip install gatana-langchain
```

Or with [uv](https://docs.astral.sh/uv/):

```bash
uv add gatana-langchain
```

## Basic usage

Create a Gatana sandbox and pass it as the `backend` to a deep agent. The agent gets filesystem tools (`ls`, `read_file`, `write_file`, `edit_file`, `glob`, `grep`) and an `execute` tool for running shell commands — all inside the sandbox.

```python
from gatana_client import AuthenticatedClient
from langchain_anthropic import ChatAnthropic

from deepagents import create_deep_agent
from gatana_langchain import GatanaSandbox

client = AuthenticatedClient(
    base_url="https://api.gatana.ai",
    token="your-gatana-api-key",
)

with GatanaSandbox(client=client) as backend:
    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": "Create a Python script that prints the Fibonacci sequence and run it",
                }
            ]
        }
    )
    print(result["messages"][-1].content)
# Sandbox is automatically deleted when the `with` block exits.
```

### Wrapping an existing sandbox

If you already have a sandbox ID (e.g. from a previous session), pass it directly. The sandbox will **not** be auto-deleted on exit:

```python
backend = GatanaSandbox(client=client, sandbox_id="existing-sandbox-id")
result = backend.execute("echo hello from existing sandbox")
print(result.output)
```

### Running commands directly

You can call `execute()` without creating an agent:

```python
with GatanaSandbox(client=client) as backend:
    result = backend.execute("python --version")
    print(result.output)   # e.g. "Python 3.12.0\n"
    print(result.exit_code)  # 0
```

### Uploading and downloading files

Seed the sandbox with files before the agent runs, or retrieve artifacts afterwards:

```python
with GatanaSandbox(client=client) as backend:
    # Upload files into the sandbox
    backend.upload_files([
        ("/src/main.py", b"print('Hello')\n"),
        ("/pyproject.toml", b"[project]\nname = 'my-app'\n"),
    ])

    # Run the agent or execute commands...
    backend.execute("cd /src && python main.py")

    # Download artifacts from the sandbox
    results = backend.download_files(["/src/main.py"])
    for r in results:
        if r.content is not None:
            print(f"{r.path}: {r.content.decode()}")
        else:
            print(f"Failed to download {r.path}: {r.error}")
```

## Development

This package is part of the [gatana-python](https://github.com/gatana-ai/gatana-langchain-sandbox) monorepo. See the root [CONTRIBUTING.md](../../CONTRIBUTING.md) for setup instructions.

## License

[MIT](../../LICENSE) — Copyright (c) 2026 Gatana
