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.3.0-cp312-cp312-win_amd64.whl (6.5 MB view details)

Uploaded CPython 3.12Windows x86-64

littrs-0.3.0-cp312-cp312-manylinux_2_34_x86_64.whl (7.4 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

littrs-0.3.0-cp312-cp312-macosx_11_0_arm64.whl (6.7 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: littrs-0.3.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 6.5 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.3.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 a53ab5fefb9ad82b136285f7fc1c6b2cf99ebbdfffec5e67d7425149487069dd
MD5 26d02dbe83e12890a8e2fd813d3873e1
BLAKE2b-256 6f91309f35a8efc79f680b818476faf96260b20bfbc741e90a10da4dbffc064f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for littrs-0.3.0-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 883974749f970fbae3bebaf6bc2e375e3419982471bee183f5b057541e851127
MD5 b67e89b1f30941bb2ea696fbe4d1de61
BLAKE2b-256 6f562729a677ba831a459f36c46e1f629bd1a88ac5f38ea6c096206dd00daeb5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for littrs-0.3.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 260e39c5d493dee58de6590019f6d4f2a4fe9b2bf532e873cfe09f93e9b6d105
MD5 e449c4af14dcfafb61a37d18d161eaf4
BLAKE2b-256 de313108772cb9eb7bd264bef9524501be9eba9235eb60c7fed76dfd81f119cc

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