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
- Policy & Registration -- configuring what sandboxed code can access
- Sandbox Execution -- running code, results, error handling
- Filesystem & Network -- VFS interception, network denial, VFS imports
- Serialization -- pickling functions, classes, and state across turns
- Security Model -- how the sandbox works, what it blocks, threat model
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
006b7411a1ff3c5c64e4bd66b68f83d26247c33f51fe3017ac2301a4eaf71d0b
|
|
| MD5 |
cfe78cffde4bc9cbc33f0146c9fcb633
|
|
| BLAKE2b-256 |
f78c07e90994832946faa5975e563773afd322a4a87740f74c234ab085511709
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f75cb63e594d7c1ce9e1a9eadfe2b5da9a67d257e52bbbeb8ec68d1719487d1f
|
|
| MD5 |
8fbc01b0ad7c306aade73e74763159ff
|
|
| BLAKE2b-256 |
d28e3eb2e9d2b3c1ed77308f0772fcd1867f02393b1bcfed3f6d9cc92642d6b8
|