Skip to main content

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.1.0.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

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

py_sandbox-0.1.0-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for py_sandbox-0.1.0.tar.gz
Algorithm Hash digest
SHA256 bccb29e62206949ef22b75ca9dcbcff1bafe7852da28a0fea076db40bdd7246b
MD5 3de6f8c5e8e5f75688bfc04107d8d299
BLAKE2b-256 9b43cc00de4b0a1fe5bf96231380d5c05c770fd18c9c6aea87513a2206bafba6

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for py_sandbox-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e6a69ee93f38f74b246a797ca77b51e01a17be1af46f3aa3b19d6ea1221c16e6
MD5 2e25e64ea3040e779cde43003f677954
BLAKE2b-256 089a322539d628ae9ea2ca3dcafb76dfe7ce79a809d029f29730eccab70d5c5e

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