vndee/llm-sandbox
Lightweight and portable LLM sandbox runtime (code interpreter) Python library.
What it solves
Running code that an AI model generates is risky — it can accidentally delete files, access the internet, or damage your system. LLM Sandbox addresses this by providing a safe, isolated environment where that code can run without endangering your host machine. It gives developers a single, simple interface to launch code in a protected container or local sandbox, with CPU, memory, time, and network limits you control.
How it works
LLM Sandbox offers a common Python API called SandboxSession. You pick a backend (Docker, Kubernetes, Podman, Bubblewrap, NsJail, Windows MXC, or WSL2 Bubblewrap), and the library launches an isolated environment (a container or a local Linux/Windows sandbox) with the language runtime you need (Python, JavaScript, Java, C++, Go, R). It then runs your code inside that environment and returns the output. You can install libraries on the fly, copy files in and out, and even capture visualizations like plots and charts. The library includes security features like network isolation, resource limits, and custom security policies. For high throughput, it also supports container pooling — reusing pre-warmed containers to avoid startup overhead, and it can be used interactively (like a Jupyter notebook) to keep state across code runs.
Who it’s for
Developers and teams building applications that use large language models to generate or execute code. This includes agent frameworks, AI assistants, and any tool that needs to run untrusted code safely. It’s particularly useful for anyone who wants a consistent way to sandbox code across different infrastructure choices — from a local laptop to a Kubernetes cluster.
Highlights
- Multiple backends: Docker, Kubernetes, Podman, and local Linux (Bubblewrap, NsJail), plus experimental Windows support via MXC and WSL2.
- Security first: Resource limits, network isolation, custom security policies, and explicit host access control.
- Multi-language: Out-of-the-box support for Python, JavaScript/Node.js, Java, C++, Go, and R with automatic dependency management.
- Artifact extraction: Automatically capture plots and visualizations generated by code.
- Container pooling: Reuse pre-warmed containers for up to 10x faster execution in concurrent workloads.
- Interactive sessions: Long-running IPython kernel for notebook-style workflows.
- MCP integration: Supports the Model Context Protocol, so MCP clients like Claude Desktop can run code in a secure sandbox.
- Framework integrations: Runnable examples for 11 agent frameworks, including OpenAI Agents SDK, LangChain, and LlamaIndex.
Related
- Project
- Project
- Project
- Dispatch
- Project