Skip to main content

Lightweight in-process Python sandbox using AST rewriting.

Project description

sandtrap ⛳

A lightweight in-process Python sandbox using AST rewriting and compiled bytecode execution. Whitelist-based policies control attribute access, imports, and resource usage. Designed as a walled garden for cooperative code (e.g. agent-generated scripts), not for adversarial inputs.

Install

pip install sandtrap

Quick start

from sandtrap import Policy, Sandbox

policy = Policy(timeout=5.0, tick_limit=100_000)

with Sandbox(policy) as sandbox:
    result = sandbox.exec("""
total = sum(range(10))
print(f"total = {total}")
""")

print(result.stdout)       # "total = 45\n"
print(result.namespace)    # {"total": 45}
print(result.error)        # None
print(result.ticks)        # 3 (fn calls: range + sum + print)

Documentation

License

MIT

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

sandtrap-0.1.0.tar.gz (59.1 kB view details)

Uploaded Source

Built Distribution

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

sandtrap-0.1.0-py3-none-any.whl (38.8 kB view details)

Uploaded Python 3

File details

Details for the file sandtrap-0.1.0.tar.gz.

File metadata

  • Download URL: sandtrap-0.1.0.tar.gz
  • Upload date:
  • Size: 59.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for sandtrap-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1b6e6d623b4aa5fb72b2d8287f65e177ac47bd3e8fcd0d5cf5b8400481dc54e8
MD5 a5758b71a4d6bdd0b65a85540c5fc3d5
BLAKE2b-256 04946d5a2b591ebb90c433a8b490648321a87b7a42704dc0a73022c6339d5abc

See more details on using hashes here.

File details

Details for the file sandtrap-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: sandtrap-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 38.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for sandtrap-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 991b27de5a34f4012bda96dc9476d0c0665ca61aea6e3ff7c6db806af82cae2c
MD5 becb5ccd59eda2eef3ac560fb6e1a4b6
BLAKE2b-256 1a5845730a465fba74cd05834662b31973e836a52c52e3c2eedecbcb8b6772ea

See more details on using hashes here.

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