langchain-withruntime
Runtime sandbox integration for Deep Agents.
Runtime runs each sandbox in a Firecracker microVM
with its own kernel. RuntimeSandbox is a Deep Agents sandbox backend: the
agent's execute, ls, read_file, write_file, edit_file, glob and
grep tools all run in one sandbox.
Quick install
pip install langchain-withruntime
This installs the Runtime SDK, withruntime,
and Deep Agents. Set RUNTIME_API_KEY to a key from
https://withruntime.com/account/keys, or run npx -y withruntime login once on
this machine. A new account starts on a free trial with no card.
Use it
from deepagents import create_deep_agent
from withruntime import Sandbox
from langchain_withruntime import RuntimeSandbox
with Sandbox.create() as sbx:
agent = create_deep_agent(
model="anthropic:claude-sonnet-4-6",
backend=RuntimeSandbox(sbx),
)
result = agent.invoke(
{"messages": [{"role": "user", "content": "Write fib.py, run it, and show the first 10 numbers."}]}
)
print(result["messages"][-1].content)
Leaving the with block stops the sandbox. The backend works on its own too:
from withruntime import Sandbox
from langchain_withruntime import RuntimeSandbox
with Sandbox.create() as sbx:
backend = RuntimeSandbox(sbx, timeout_seconds=300)
print(backend.execute("python3 --version").output)
backend.write("/workspace/notes.txt", "hello\n")
print(backend.read("/workspace/notes.txt").file_data["content"])
timeout_seconds(default 1800) is the limit for a command that names none; a command that runs past it is stopped and its output says so.max_output_chars(default 100,000) keeps the end of a longer output and marks it truncated.Sandbox.create()takes the sandbox's settings:image,region,vcpu,memory_mib,timeout_seconds(its lease),networkand more. See the Python SDK guide.
Deep Agents Code
The package registers a runtime sandbox provider for Deep Agents Code:
dcode install langchain-withruntime --package
dcode --sandbox runtime
Each session gets a new sandbox, stopped when the session ends.
--sandbox-id <id> attaches to a sandbox that is already running and leaves it
running. RuntimeProvider is the same
lifecycle in code:
from langchain_withruntime import RuntimeProvider
provider = RuntimeProvider()
backend = provider.get_or_create(timeout=900) # a new sandbox with a 15 minute lease
try:
print(backend.execute("uname -r").output)
finally:
provider.delete(sandbox_id=backend.id)
Where it comes from
RuntimeSandbox is maintained in the Runtime SDK as withruntime.deepagents
(pip install "withruntime[deepagents]" gives the same class). This package
installs it under the langchain-<provider> name the other Deep Agents sandbox
packages use and adds the Deep Agents Code provider.
Tests
pip install -e . pytest pytest-asyncio langchain-tests
pytest tests/unit_tests # offline
RUNTIME_API_KEY=... pytest tests/integration_tests # real sandboxes
RUNTIME_API_KEY=... python scripts/e2e.py # a Deep Agent with a scripted model
The offline tests run LangChain's standard SandboxIntegrationTests against a
stand-in sandbox that executes on the local machine (Linux).
Documentation
License
Apache-2.0
Release files for langchain-withruntime 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| langchain_withruntime-0.1.0.tar.gz | 15.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| langchain_withruntime-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 25.6 kB
Release files / langchain_withruntime-0.1.0.tar.gz
| Download URL | langchain_withruntime-0.1.0.tar.gz |
|---|---|
| Size | 15.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
08901f8b5c8485be01118ff41e1711003955becfd188d362c3f6a9c37f8273e8
|
|
BLAKE2b-256 checksum How to use checksums |
820132d5612e97eda9303596aa2fdb7b5a4bd872bcbdb4ae7c1afcf38aecde5c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / langchain_withruntime-0.1.0-py3-none-any.whl
| Download URL | langchain_withruntime-0.1.0-py3-none-any.whl |
|---|---|
| Size | 10.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5ac7746765cf457a314e8e9e4c4a9180188a0fe2e86a6377b9265afa6048318b
|
|
BLAKE2b-256 checksum How to use checksums |
e7e4736419103397c3f4f35deaebe2cc998bcf1275fe8e6a8b6b582bbada97b9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|