Execute untrusted Python code safely with caching and remote loading
Project description
py-sandbox
Execute untrusted Python code safely with isolation, caching, and integrity verification.
Installation
pip install py-sandbox
Quick Start
from py_sandbox import run
result = run('''
x = [1, 2, 3, 4, 5]
result = sum(x) * 2
print(f"Calculated: {result}")
''')
print(result['stdout']) # "Calculated: 30"
print(result['result']) # 30
print(result['success']) # True
Security
Dangerous operations are automatically blocked:
result = run("import os; os.system('rm -rf /')" )
print(result['success']) # False
print(result['stderr']) # "Import 'os' blocked for security"
Static Analysis
Check code before running:
from py_sandbox import check
analysis = check("import subprocess; subprocess.call(['ls'])")
print(analysis['safe']) # False
print(analysis['warnings']) # ['Subprocess access attempt']
Caching
from py_sandbox import cache
cache.set("key", {"data": 123}, ttl=3600)
value = cache.get("key")
cache.delete("key")
cache.clear()
print(cache.stats())
Integrity Verification
from py_sandbox import verify
hash = verify.sign("my content")
assert verify.check("my content", hash)
Remote Loading
Load modules from authenticated endpoints:
from py_sandbox import remote
remote.configure(
endpoint="https://your-server.com/modules",
api_key="your-key"
)
module = remote.load("module_name")
Environment Variables
export PY_SANDBOX_ENDPOINT="https://your-server.com/modules"
export PY_SANDBOX_KEY="your-key"
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
py_sandbox-0.2.0.tar.gz
(7.4 kB
view details)
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 py_sandbox-0.2.0.tar.gz.
File metadata
- Download URL: py_sandbox-0.2.0.tar.gz
- Upload date:
- Size: 7.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
803cc177e3687c1c2bc055dc2cfdb83130ae085177d1d65cac51f58a1e778ca4
|
|
| MD5 |
a2e803e7bb05e987e5218c12a856cab0
|
|
| BLAKE2b-256 |
871864208c4a3b8ee2baf93c337882a5c89af1e579248326c25837fbb9089289
|
File details
Details for the file py_sandbox-0.2.0-py3-none-any.whl.
File metadata
- Download URL: py_sandbox-0.2.0-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b5a99fbe060b31bfd3f68a909b4285a3462b9146b5d82b960b2a5b853cfbcb2f
|
|
| MD5 |
57baa7f46dfd3cfb0d4dd787db2c88e5
|
|
| BLAKE2b-256 |
14f71c8f7529342f52fb16a9774769644c40982bebc98824773fc5ba99f2be34
|