Skip to main content

A minimal, secure Python sandbox for AI agents

Project description

littrs

A minimal, secure Python sandbox for AI agents.

Installation

pip install littrs

Quick Start

from littrs import Sandbox, WasmSandbox

# Simple sandbox (fast, in-process)
sandbox = Sandbox()
sandbox.execute("x = 10")
result = sandbox.execute("x * 2")
print(result)  # 20

# WASM sandbox (stronger isolation, recommended for untrusted code)
wasm = WasmSandbox()
result = wasm.execute("sum(range(100))")
print(result)  # 4950

Features

  • Secure by default: No file system, network, or OS access
  • Two isolation levels:
    • Sandbox: Fast, in-process execution
    • WasmSandbox: WebAssembly isolation (recommended for untrusted code)
  • Tool registration: Register Python functions callable from the sandbox
  • Resource limits: Control computation (fuel) and memory usage

Registering Tools

from littrs import Sandbox

def fetch_data(args):
    id = args[0] if args else 0
    return {"id": id, "name": "Example"}

sandbox = Sandbox()
sandbox.register_function("fetch_data", fetch_data)

result = sandbox.execute("fetch_data(42)")
print(result)  # {'id': 42, 'name': 'Example'}

WASM Sandbox with Limits

from littrs import WasmSandbox, WasmSandboxConfig

# Configure resource limits
config = WasmSandboxConfig() \
    .with_fuel(1_000_000) \
    .with_max_memory(32 * 1024 * 1024)  # 32MB

sandbox = WasmSandbox(config)

# This will run out of fuel and raise an error
try:
    sandbox.execute("while True: pass")
except RuntimeError as e:
    print("Stopped:", e)

Supported Python Features

  • Basic types: None, bool, int, float, str, list, dict
  • Arithmetic, comparison, and boolean operators
  • Control flow: if/elif/else, for, while
  • Built-in functions: len(), range(), str(), int(), print(), etc.

Not Supported

  • import statements
  • Class definitions
  • File I/O
  • Network access
  • Any standard library

License

Apache-2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

littrs-0.4.0-cp312-cp312-win_amd64.whl (7.9 MB view details)

Uploaded CPython 3.12Windows x86-64

littrs-0.4.0-cp312-cp312-manylinux_2_34_x86_64.whl (9.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

littrs-0.4.0-cp312-cp312-macosx_11_0_arm64.whl (7.8 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

File details

Details for the file littrs-0.4.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: littrs-0.4.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 7.9 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for littrs-0.4.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 493de52145fc9aa78d009a2518db9a6ed5c270637aefcaabb93ad69b66942995
MD5 4a660b3de6e1a6f6fd610ac0e24a5035
BLAKE2b-256 e3a1542d1d7e2b13650a41246e35fe30bb069936812325acba7f285b50a809f9

See more details on using hashes here.

File details

Details for the file littrs-0.4.0-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for littrs-0.4.0-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 af5917846eefb565d4a4ed2684209b9456ec87e9628f77a54ac87fdc05c56e5e
MD5 1d8905d8a545531bd1539815150a3b60
BLAKE2b-256 81829380cc5709abad0b379b48abc0ef24420a0e127a3c5fefa269d6ac8a639e

See more details on using hashes here.

File details

Details for the file littrs-0.4.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for littrs-0.4.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4d3b0c23b5752fde9121f3fbc6111b438849f37e8b1e0a5a891d59d20b7759db
MD5 48b20d006b18a3f6f40b76872b07cf0b
BLAKE2b-256 4d59742f9d3e9d0fab09c110e961b23d978390d21ec015e19702b74f0ceffc91

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