Skip to main content

Lightning AI sandbox integration for Deep Agents

Project description

langchain-lightning

PyPI - Version PyPI - License PyPI - Downloads

Lightning AI sandbox integration for Deep Agents.

Quick Install

pip install langchain-lightning

Deep Agents SDK

from lightning_sdk.sandbox import Sandbox
from langchain_lightning import LightningSandbox, ensure_workdir

# python313 ships python3, which Deep Agents file tools require.
sandbox = Sandbox.create(
    instance_type="cpu-1",
    runtime="python313",
    persistent=True,  # optional: stop/resume by id across runs
)
ensure_workdir(sandbox, "/root")
backend = LightningSandbox(sandbox=sandbox)

try:
    result = backend.execute("python3 --version && echo hello")
    print(result.output)
finally:
    sandbox.delete()

Reconnect to a durable sandbox (auto-resumes when paused):

from lightning_sdk.sandbox import Sandbox
from langchain_lightning import LightningSandbox, ensure_workdir, resume_if_needed

sandbox = resume_if_needed(Sandbox().get("sbx_..."))
ensure_workdir(sandbox, "/root")
backend = LightningSandbox(sandbox=sandbox)

The backend also works with async Deep Agents via the inherited aexecute, aupload_files, adownload_files, and related methods (the Lightning SDK is synchronous, so these run on a worker thread).

Deep Agents Code

Install langchain-lightning into the dcode environment, then run with the Lightning sandbox provider:

dcode --install langchain-lightning --package
export LIGHTNING_API_KEY=...
dcode --sandbox lightning

The provider defaults:

Setting Default
runtime python313 (has python3)
instance type cpu-1
sandbox lifetime 30 minutes
workdir /root
persistent false

Optional env vars: LIGHTNING_SANDBOX_RUNTIME, LIGHTNING_SANDBOX_IMAGE, LIGHTNING_SANDBOX_INSTANCE_TYPE, LIGHTNING_SANDBOX_TIMEOUT (seconds), LIGHTNING_SANDBOX_PERSISTENT, LIGHTNING_SANDBOX_NETWORK_POLICY, LIGHTNING_CLOUD_URL.

When reconnecting by sandbox id, the provider resumes paused/stopped persistent sandboxes and ensures the workdir exists.

What is this?

langchain-lightning adapts an existing Lightning AI sandbox to the Deep Agents sandbox protocol. It implements the execute, upload_files, and download_files primitives over the lightning_sdk.sandbox SDK; Deep Agents derives the rest of the filesystem operations (ls, read, write, edit, grep, glob) from those.

Commands run detached and are awaited so per-command timeouts are honored. File transfer is bridged through base64 so arbitrary binary content round-trips losslessly despite Lightning's text-based file API.

For SDK use, this package intentionally does not hide Lightning sandbox lifecycle management. Use the Lightning SDK to create, connect to, configure, and delete sandboxes, then pass the sandbox object to LightningSandbox.

For Deep Agents Code, the package also exposes a dcode sandbox provider entry point. The provider creates, reconnects to, and deletes Lightning sandboxes for dcode --sandbox lightning.

[!NOTE] Deep Agents runs its file operations with python3 inside the sandbox, so create sandboxes with a runtime that ships a Python interpreter (e.g. runtime="python313", the default for the provider). The bare default CPU image does not include Python.

Contributing

Contributions are welcome. Keep the adapter focused on implementing the Deep Agents sandbox backend protocol over the official Lightning SDK.

Development

uv sync --group test
make test
make lint

Integration tests require LIGHTNING_API_KEY and hit the real Lightning API (create / shell / files / pause-resume):

export LIGHTNING_API_KEY=...
make integration_tests

CI runs unit tests on every PR and live integration tests when the LIGHTNING_API_KEY repository secret is available (same-repo PRs, pushes to main, nightly schedule, and manual workflow_dispatch).

Project details


Download files

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

Source Distribution

langchain_lightning-1.0.0.tar.gz (245.9 kB view details)

Uploaded Source

Built Distribution

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

langchain_lightning-1.0.0-py3-none-any.whl (14.4 kB view details)

Uploaded Python 3

File details

Details for the file langchain_lightning-1.0.0.tar.gz.

File metadata

  • Download URL: langchain_lightning-1.0.0.tar.gz
  • Upload date:
  • Size: 245.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for langchain_lightning-1.0.0.tar.gz
Algorithm Hash digest
SHA256 17599c2e79ef5a1ae8f974baa07ab95e4570c4c5b60dbd2b7cd5ca16b25849c5
MD5 0c6468b56493b9075ae8580dee8af503
BLAKE2b-256 d7a636d223980c3d7140c13cd08fdd402a9e2c86e8876be9e02c482a48e7c2cd

See more details on using hashes here.

Provenance

The following attestation bundles were made for langchain_lightning-1.0.0.tar.gz:

Publisher: release.yml on Lightning-AI/langchain-lightning

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_lightning-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_lightning-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1a97c0124c5d0bde59bbce20f73abdcf4576051634c7f39f5b5fbe38f4153b07
MD5 0201606123c64d78933e187e416e1a9f
BLAKE2b-256 984185a657530f7f4df33ee4274039dddc0b253d61890168056753a4d2521ed6

See more details on using hashes here.

Provenance

The following attestation bundles were made for langchain_lightning-1.0.0-py3-none-any.whl:

Publisher: release.yml on Lightning-AI/langchain-lightning

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

Supported by

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