LLM Sandbox is a lightweight and portable Python library designed to run large language model (LLM) generated code in a safe and isolated environment. It supports various container backends like Docker, Kubernetes, and Podman, and offers multi-language execution (Python, JavaScript, Java, C++, Go, R). The project sees frequent minor releases, addressing features, fixes, and security enhancements, and now supports the Model Context Protocol (MCP) server for direct AI assistant integration.
pip install llm-sandboxVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to create a `SandboxSession` for Python, execute code, and optionally specify libraries. It includes error handling for common setup issues like the container backend not running.
Upgrade to `llm-sandbox>=0.3.35`.
Upgrade to `llm-sandbox>=0.3.32`. Carefully review environment configuration for pooled sessions and fast production modes.
Install `llm-sandbox` with the correct extra, e.g., `pip install 'llm-sandbox[docker]'`.
Understand the lifecycle of `SandboxSession` and use features like `keep_template` or `SandboxPoolManager` for state management if persistence is required. Refer to documentation for advanced usage.
Install the library using pip: `pip install llm-sandbox`. If using specific backends, install with extras, e.g., `pip install 'llm-sandbox[docker]'`.
When creating the `SandboxSession`, specify the required libraries using the `libraries` parameter: `session = SandboxSession(lang="python", libraries=["numpy"])`.
Ensure Docker Desktop or the Docker daemon is running and properly configured on your system. Check Docker's logs for more specific connection issues.
Correct the import statement to use `SandboxSession`: `from llm_sandbox import SandboxSession`.
Increase the `timeout` parameter when creating the `SandboxSession` or when calling `session.run()`: `session = SandboxSession(lang="python", timeout=60)` or `result = session.run("long_running_code()", timeout=120)`.