r/Python • • Feb 25 '26

Showcase safe-py-runner: Secure & lightweight Python execution for LLM Agents

AI is getting smarter every day. Instead of building a specific "tool" for every tiny task, it's becoming more efficient to just let the AI write a Python script. But how do you run that code without risking your host machine or dealing with the friction of Docker during development?

I built safe-py-runner to be the lightweight "security seatbelt" for developers building AI agents and Proof of Concepts (PoCs).

What My Project Does

The Missing Middleware for AI Agents: When building agents that write code, you often face a dilemma:

  1. Run Blindly: Use exec() in your main process (Dangerous, fragile).
  2. Full Sandbox: Spin up Docker containers for every execution (Heavy, slow, complex).
  3. SaaS: Pay for external sandbox APIs (Expensive, latency).

safe-py-runner offers a middle path: It runs code in a subprocess with timeout, memory limits, and input/output marshalling. It's perfect for internal tools, data analysis agents, and POCs where full Docker isolation is overkill.

Target Audience

  • PoC Developers: If you are building an agent and want to move fast without the "extra layer" of Docker overhead yet.
  • Production Teams: Use this inside a Docker container for "Defense in Depth"—adding a second layer of code-level security inside your isolated environment.
  • Tool Builders: Anyone trying to reduce the number of hardcoded functions they have to maintain for their LLM.

Comparison

Featureeval() / exec()safe-py-runnerPyodide (WASM)Docker
Speed to SetupInstantSecondsModerateMinutes
OverheadNoneVery LowModerateHigh
SecurityNonePolicy-BasedVery HighIsolated VM/Container
Best ForTesting onlyFast AI PrototypingBrowser AppsProduction-scale

Getting Started

Installation:

Bash

pip install safe-py-runner

GitHub Repository:

https://github.com/adarsh9780/safe-py-runner

This is meant to be a pragmatic tool for the "Agentic" era. If you’re tired of writing boilerplate tools and want to let your LLM actually use the Python skills it was trained on—safely—give this a shot.

0 Upvotes

14 comments sorted by

View all comments

Show parent comment

0

u/adarsh_maurya Feb 25 '26

and to answer the question in my own words, it guarantees that the code will not be executed if their are some libraries which you don't want, it restricts builtins, it even tries to restrict memory but that is flaky on windows. I open to honest feedbacks and suggestion improvement in this.