langchain-sandbox
StaleDescription
Safely run untrusted Python code in LangChain agents using Pyodide and Deno as isolated execution runtimes.
Key Features
- Pyodide sandbox - Execute arbitrary Python in a Pyodide-isolated runtime inside Node or browser
- Deno backend - Ships with a permission-scoped Deno runtime for JavaScript/TypeScript execution
- Tool wrapper - One line to expose the sandbox as a LangChain Tool for agents
- Stateful execution - Global variables persist across calls, ideal for multi-step exploration
- Secure defaults - Network and filesystem access denied by default, opt-in per session
Use Cases
💡 Let LangChain or LangGraph agents safely execute LLM-generated Python
💡 Provide an isolated code-interpreter tool for untrusted model output
💡 Offer a stateful execution environment for multi-step data analysis
💡 Replace unsafe exec/eval when running model-produced code in production
Categories
Quick Start
# Install langchain-sandbox
pip install langchain-sandbox
# Expose as a LangChain tool
from langchain_sandbox import PyodideSandboxTool
sandbox = PyodideSandboxTool()
print(sandbox.invoke("print(2+2)"))