LangChain tool for running Python in disposable-exec isolated containers
This project has been archived.
The maintainers of this project have marked this project as archived. No new releases are expected.
Project description
langchain-disposable
Give your LangChain agent a code execution tool that runs in an isolated container — no network, read-only filesystem, 30-second timeout. Every run is disposable.
When to use it
Use this package if you already use LangChain and want:
- a LangChain tool for remote execution
- API-key-authenticated execution through Disposable Exec
- the standard Disposable Exec flow behind a LangChain-facing interface
If you just need the raw client, use disposable-exec.
Install
pip install langchain-disposable disposable-exec
For the agent example, also install the LangChain packages and model provider package you already use.
Environment variables
export DISPOSABLE_EXEC_BASE_URL="https://your-api-host"
export DISPOSABLE_EXEC_API_KEY="de_xxx"
Minimal tool example
import os
from langchain_disposable import DisposableExecTool
tool = DisposableExecTool(
api_key=os.environ["DISPOSABLE_EXEC_API_KEY"],
base_url=os.environ["DISPOSABLE_EXEC_BASE_URL"],
)
result = tool.invoke({"script": "print(2 + 2)"})
print(result)
Minimal agent example
import os
from langchain.agents import AgentExecutor, create_tool_calling_agent
from langchain_core.prompts import ChatPromptTemplate
from langchain_openai import ChatOpenAI
from langchain_disposable import DisposableExecTool
tool = DisposableExecTool(
api_key=os.environ["DISPOSABLE_EXEC_API_KEY"],
base_url=os.environ["DISPOSABLE_EXEC_BASE_URL"],
)
prompt = ChatPromptTemplate.from_messages(
[
("system", "Use the execution tool when Python is useful."),
("human", "{input}"),
("placeholder", "{agent_scratchpad}"),
]
)
agent = create_tool_calling_agent(ChatOpenAI(model="gpt-4o-mini"), [tool], prompt)
executor = AgentExecutor(agent=agent, tools=[tool], verbose=True)
print(executor.invoke({"input": "Use Python to compute the mean of [2, 4, 6, 8]."}))
What the agent gets back
The tool returns a JSON string with:
stdout— captured standard outputstderr— captured standard errorexit_code— process exit code (0 = success)failure_reason— structured reason if failed:timeout,exit_nonzero,sandbox_error,platform_error,orphanedduration— execution time in seconds
Your agent can use failure_reason to decide whether to retry, rewrite the code, or give up.
Relationship to Disposable Exec
langchain-disposable is a thin LangChain wrapper on top of disposable-exec. Disposable Exec provides the API key, /me, /run, /status, and /result flow. This package makes that flow easy to use from LangChain.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file langchain_disposable-0.1.1.tar.gz.
File metadata
- Download URL: langchain_disposable-0.1.1.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d2da08aad34056a1149b451a0ecd466dfba2fa75fd13e564b5528c1e06157e7
|
|
| MD5 |
140d8444ab387f04714fce73d6854ce1
|
|
| BLAKE2b-256 |
ca4785bb80c2071f7d518dca467df46b6d264a2281329d899f5c67ba132d6fb8
|
File details
Details for the file langchain_disposable-0.1.1-py3-none-any.whl.
File metadata
- Download URL: langchain_disposable-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0d3e690026dfaef1e5f46c16c7a2d839bf8589c123b969b6e42693cb29f9124b
|
|
| MD5 |
20976f5cdc28d939f777e64342bdfb05
|
|
| BLAKE2b-256 |
8118b8e5d1be2f7362d4b7d222c92b5cff59c06c641e77fb4daf738d8f208f09
|