Skip to main content

langchain-sandbox-opensandbox

PyPI - Version PyPI - License PyPI - Downloads

OpenSandbox sandbox integration for Deep Agents.

Quick Install

uv add langchain-sandbox-opensandbox

The distribution is published as langchain-sandbox-opensandbox, but the import package is langchain_opensandbox.

from opensandbox import SandboxSync

from langchain_opensandbox import OpenSandboxBackend

sandbox = SandboxSync.create("python:3.12")
backend = OpenSandboxBackend(sandbox=sandbox, timeout=300)

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

Using it with Deep Agents

Pass the backend to a Deep Agent so the agent's file and shell tools run inside the OpenSandbox environment instead of on the host:

from deepagents import create_deep_agent
from opensandbox import SandboxSync

from langchain_opensandbox import OpenSandboxBackend

# 1. Spin up a sandbox and wrap it.
sandbox = SandboxSync.create("python:3.12")
backend = OpenSandboxBackend(sandbox=sandbox, timeout=300)

# 2. Hand the backend to the agent. Every ls / read_file / write_file /
#    glob / grep / execute the agent performs is now sandboxed.
agent = create_deep_agent(
    tools=[],
    system_prompt="You are a coding assistant. Use the sandbox to run code.",
    backend=backend,
)

result = agent.invoke(
    {"messages": [{"role": "user", "content": "Create hello.py and run it."}]}
)
print(result["messages"][-1].content)

# 3. Tear the sandbox down when you're done. destroy() terminates the remote
#    sandbox and closes local resources (kill() alone leaves the local
#    transport open).
sandbox.destroy()

The higher-level file helpers the agent calls (ls, read_file, write_file, glob, grep) are provided by BaseSandbox and built on top of the three primitives this adapter implements (execute, upload_files, download_files).

🤔 What is this?

OpenSandboxBackend adapts the OpenSandbox Python SDK to the BaseSandbox interface used by Deep Agents, so you can run agent-generated commands and file operations inside an OpenSandbox environment.

It implements the three sandbox primitives — execute, upload_files, and download_files — on top of the OpenSandbox SDK. The higher-level file helpers (ls, read_file, write_file, glob, grep) are provided by BaseSandbox and built on top of execute.

Configuration

OpenSandboxBackend wraps an existing opensandbox.SandboxSync instance, so it inherits whatever connection you configured on the SDK. To point at a specific server, build a ConnectionConfigSync and pass it to SandboxSync.create:

from opensandbox import SandboxSync
from opensandbox.config.connection_sync import ConnectionConfigSync

from langchain_opensandbox import OpenSandboxBackend

connection = ConnectionConfigSync(
    domain="127.0.0.1:8080",  # host (and optional port) of the server
    protocol="http",          # "http" or "https"
    api_key="my-api-key",     # if the server requires authentication
)
sandbox = SandboxSync.create("python:3.12", connection_config=connection)
backend = OpenSandboxBackend(sandbox=sandbox)

Running a local OpenSandbox server

The integration tests (and the snippets above) need a reachable OpenSandbox server. You can run one locally with Docker:

# Requires Docker to be running.
uvx opensandbox-server init-config ./os-sandbox.toml --example docker
uvx opensandbox-server --config ./os-sandbox.toml

This starts the management API on 127.0.0.1:8080. Set an api_key in the generated config if you want authentication; otherwise the server starts in insecure mode. Then point the SDK at it with domain="127.0.0.1:8080" and protocol="http" as shown above.

Development

uv sync
make lint            # ruff check + format --diff
make test            # unit tests (no network)
make integration_tests   # conformance suite (requires a running OpenSandbox server)
make build           # build wheel + sdist

Conformance

The integration tests run the standard SandboxIntegrationTests conformance suite from langchain-tests — the same suite every Deep Agents sandbox backend is validated against. It exercises execute, file upload/download, and all the inherited helpers (ls, read_file, write_file, glob, grep) with real I/O, including large payloads, escaped content, error handling, and both the sync and async paths.

This adapter passes the full suite (86/86) against a live OpenSandbox server — no mocks, no skips:

OPENSANDBOX_DOMAIN=127.0.0.1:8080 \
OPENSANDBOX_PROTOCOL=http \
OPENSANDBOX_API_KEY=<your-key> \
make integration_tests

The suite is skipped automatically unless OPENSANDBOX_DOMAIN is set, so make test stays offline and fast.

Releases & Versioning

This package follows semantic versioning.

Contributing

Contributions are welcome. Please open an issue or pull request on GitHub.

License

Apache License 2.0. See LICENSE.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langchain_sandbox_opensandbox-0.1.2.tar.gz (163.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langchain_sandbox_opensandbox-0.1.2-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

Details for the file langchain_sandbox_opensandbox-0.1.2.tar.gz.

File metadata

File hashes

Hashes for langchain_sandbox_opensandbox-0.1.2.tar.gz
Algorithm Hash digest
SHA256 29085ebdba88b07737db9cf411b1ec3e0f9d5ae4ddd50bb6f8ab726f27ec575e
MD5 8866b733cbfe8ff600354e9f34dbf584
BLAKE2b-256 4c3d16dc11e76562677a0281a68b87f30cd91c9d001dd6f68b77f0e72dfdca0b

See more details on using hashes here.

Provenance

The following attestation bundles were made for langchain_sandbox_opensandbox-0.1.2.tar.gz:

Publisher: release.yml on AyushSonuu/langchain-sandbox-opensandbox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file langchain_sandbox_opensandbox-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_sandbox_opensandbox-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 29649e594f7a3d8406789555c31b1969cff893a916ae21c924de2db7633c9b30
MD5 29015a42e802a914418e00f860a6a9c1
BLAKE2b-256 83c22b28527a9e834b88dcc3c0ada40e65a4d1a1b80fc412964fcb92eb1fbb61

See more details on using hashes here.

Provenance

The following attestation bundles were made for langchain_sandbox_opensandbox-0.1.2-py3-none-any.whl:

Publisher: release.yml on AyushSonuu/langchain-sandbox-opensandbox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 files

0.1.1

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page