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.2.tar.gz (58.9 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.2-py3-none-any.whl (38.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sandtrap-0.1.2.tar.gz
  • Upload date:
  • Size: 58.9 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.2.tar.gz
Algorithm Hash digest
SHA256 006b7411a1ff3c5c64e4bd66b68f83d26247c33f51fe3017ac2301a4eaf71d0b
MD5 cfe78cffde4bc9cbc33f0146c9fcb633
BLAKE2b-256 f78c07e90994832946faa5975e563773afd322a4a87740f74c234ab085511709

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sandtrap-0.1.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f75cb63e594d7c1ce9e1a9eadfe2b5da9a67d257e52bbbeb8ec68d1719487d1f
MD5 8fbc01b0ad7c306aade73e74763159ff
BLAKE2b-256 d28e3eb2e9d2b3c1ed77308f0772fcd1867f02393b1bcfed3f6d9cc92642d6b8

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