How langchain-ai/langchain-sandbox works
Project type and purpose
• This is a language-agnostic sandboxing library (“LangChain Sandbox”) that allows Python code to run securely in a local, in-memory Pyodide (WebAssembly) environment invoked from Python via a Deno-based JavaScript/TypeScript module.
• It exposes a Python API (PyodideSandbox, PyodideSandboxTool) and integrates with LangChain/LangGraph agents as a tool for safe execution of untrusted code.
File structure
• Top-level: .github/ (CI, lint, release workflows), examples/, libs/.
• libs/pyodide-sandbox-js: a standalone Deno project (TypeScript) implementing the core WebAssembly sandbox.
• libs/sandbox-py: a Python package wrapping and driving the JS sandbox via subprocess calls. Contains langchain_sandbox/pyodide.py (wrapper logic), pyproject.toml, and unit tests.
README for additional insights
• Two main components:
• pyodide-sandbox-js (Deno + TypeScript + Pyodide WASM)
• sandbox-py (Python wrapper, uses subprocess to invoke the JS sandbox)
• Usage patterns: direct Python API, LangChain tool, LangGraph agent integration (stateful vs. stateless).