AgentRun logo

AgentRun

Free

The easiest, and fastest way to run AI-generated Python code safely ![GitHub Repo stars](https://img.shields.io/github/stars/Jonathan-Adly/AgentRun?style=social)

FreeFree tier
Type
Open Source

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

Safe code execution with dangerous element checking before execution
Isolated execution in fully configured Docker containers
Configurable resource management (CPU, memory) with sane defaults
Execution timeouts to prevent runaway scripts
Complete dependency management: install, uninstall, and cache packages
Dependency caching to optimize performance across runs
Automatic cleanup of artifacts created by generated code
Comes with a pre-configured REST API and Docker Compose for self-hosting
Transparent exception handling – returns Python tracebacks, not Docker errors
97% test coverage and full static typing with only two dependencies

Pros & Cons

Pros
  • 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)
Cons
  • 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

Best For

Enabling LLMs to perform accurate mathematical calculations by executing codeAllowing LLMs to retrieve and process real-time data (e.g., stock prices) via code executionRunning AI-generated scripts in sandboxed environments for research or prototypingIntegrating safe code execution into agent frameworks or chatbotsExecuting untrusted Python code from users or third-party sources securely

FAQ

What is AgentRun?
AgentRun is an open-source Python library for safely executing AI-generated Python code. It uses Docker for isolation and RestrictedPython for code safety checks.
How does AgentRun ensure code safety?
It checks generated code for dangerous elements (e.g., file deletion commands) before execution and runs it inside an isolated Docker container with resource limits and timeouts.
What are the dependencies of AgentRun?
AgentRun has only two dependencies: the Docker Python SDK and RestrictedPython.
Does AgentRun support dependency caching?
Yes, you can cache any dependency in the Docker container in advance to optimize performance across multiple runs.
Is there a REST API for AgentRun?
Yes, the repository includes a pre-configured Docker Compose setup and a REST API, making it easy to deploy AgentRun as a standalone service without writing additional code.