AgentRun
FreeThe easiest, and fastest way to run AI-generated Python code safely 
About AgentRun
AgentRun is an open-source Python library that enables safe execution of AI-generated Python code from large language models (LLMs) with a single line of code. Built on the Docker Python SDK and RestrictedPython, it provides an isolated Docker container for code execution, automatically manages dependencies (install, uninstall, cache), limits resource consumption, checks for dangerous code patterns, and enforces execution timeouts. It features transparent exception handling, returning Python-style output and tracebacks instead of cryptic Docker messages. AgentRun offers both a pip package for custom Docker setups and a pre-configured REST API with Docker Compose for easy self-hosting. The library boasts 97% test coverage, full static typing, and only two dependencies.
Key Features
Pros & Cons
- Single-line integration to give any LLM code execution ability
- Docker-based isolation prevents harmful operations (e.g., file deletion)
- Automatic dependency handling reduces manual setup overhead
- Caching dependencies speeds up repeated runs significantly
- Works both as a Python library and via REST API for flexible deployment
- Transparent error output simplifies debugging for developers
- Lightweight – only two dependencies (Docker SDK and RestrictedPython)
- Requires Docker to be installed and running for isolated execution
- Limited to executing Python code only
- Self-hosting the REST API may require additional infrastructure management
- Docker container startup adds slight overhead compared to native execution