Skip to main content

Restricted Python execution runner with subprocess isolation, timeout, memory caps, and import/global controls

Project description

safe-py-runner

A lightweight, secure-by-default Python code runner designed for LLM agents.

GitHub Repository

Why This Package

When building agents that execute generated Python code, you often choose between:

  1. Running code directly in your process (exec) - risky.
  2. Full container sandboxing - heavier and slower.
  3. External sandbox APIs - added cost and latency.

safe-py-runner provides a practical middle path:

  • subprocess isolation
  • timeout enforcement
  • memory limits (POSIX)
  • import/builtin restrictions
  • JSON-safe input/output handling

Installation

pip install safe-py-runner

Quick Start

from safe_py_runner import RunnerPolicy, run_code

policy = RunnerPolicy(
    timeout_seconds=5,
    memory_limit_mb=128,
    blocked_imports=["os", "subprocess", "socket"],
)

result = run_code(
    code="import math\nresult = math.sqrt(input_data['x'])",
    input_data={"x": 81},
    policy=policy,
)

if result.ok:
    print(result.result)  # 9.0
else:
    print(result.error)

Security Note

This is not an OS-level sandbox.
For untrusted hostile code, use container/VM isolation in addition to this package.

More Information

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

safe_py_runner-0.1.5.tar.gz (30.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

safe_py_runner-0.1.5-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file safe_py_runner-0.1.5.tar.gz.

File metadata

  • Download URL: safe_py_runner-0.1.5.tar.gz
  • Upload date:
  • Size: 30.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for safe_py_runner-0.1.5.tar.gz
Algorithm Hash digest
SHA256 9a42c8f44068e585a0c1b1d4cb5599d1b9538f46035e6a4c721b944850b0587e
MD5 0a72c1a81cdcae596153d693662ba300
BLAKE2b-256 22309f5485a4958f71715f770a2bb30f23956c7e3b180ef111d3f404a884fbc3

See more details on using hashes here.

Provenance

The following attestation bundles were made for safe_py_runner-0.1.5.tar.gz:

Publisher: release.yml on adarsh9780/safe-py-runner

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file safe_py_runner-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: safe_py_runner-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for safe_py_runner-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 eaf9da28a5a825ac4c35536e88ab7c7ad50e58ce8311ab0f67f0700a533a2fdb
MD5 041065d8fff34f0ce295da2076af73a3
BLAKE2b-256 4580df2fca8c0f161f9f979e2eef2437b2245ab3ed1ab15acf2c533ecfeb5895

See more details on using hashes here.

Provenance

The following attestation bundles were made for safe_py_runner-0.1.5-py3-none-any.whl:

Publisher: release.yml on adarsh9780/safe-py-runner

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page