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

Uploaded CPython 3.12Windows x86-64

littrs-0.2.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.2.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.2.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: littrs-0.2.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 6.4 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.2.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 f280eb1b9e84405fb9b22033db3ef6f4036e475f45ffc1521ff4c7ffbf77922c
MD5 da0e59ba96ae2212eeb69616c7faf8af
BLAKE2b-256 20a60c50486a43c3cc5b42ad80895d0d19d6075ed9573bde965d18890c0d7364

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for littrs-0.2.0-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 904fa03c238266f3cc2bcbddfb52b2f857121015603286646743bc64d518aedb
MD5 4ec6096f412c004c37978f9bc956817f
BLAKE2b-256 121514945383f08a0d794b7c91a9060629e49a21c1209b6c54ac2177dbed63ea

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for littrs-0.2.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 06cc3ee143eddf3e904ae006fc54d7d4aa02e19402127a90fb7d03718068d64a
MD5 e47087ea01a0691c7b28701267c02767
BLAKE2b-256 1d462796283dcfb05d49bf5d9fd174adf69b836af70d9f3198abd52c31b1ab29

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