Secure WASM runtime to isolate and manage AI agent tasks
Project description
capsule-run
A secure, durable runtime for agentic workflows
Overview
Capsule is a runtime for coordinating AI agent tasks in isolated environments. It is designed to handle long-running workflows, large-scale processing, autonomous decision-making securely, or even multi-agent systems.
Each task runs inside its own WebAssembly sandbox, providing:
- Isolated execution: Each task runs isolated from your host system
- Resource limits: Set CPU, memory, and timeout limits per task
- Automatic retries: Handle failures without manual intervention
- Lifecycle tracking: Monitor which tasks are running, completed, or failed
Installation
pip install capsule-run
Quick Start
Create hello.py:
from capsule import task
@task(name="main", compute="LOW", ram="64MB")
def main() -> str:
return "Hello from Capsule!"
Run it:
capsule run hello.py
How It Works
Simply annotate your Python functions with the @task decorator:
from capsule import task
@task(name="analyze_data", compute="MEDIUM", ram="512MB", timeout="30s", max_retries=1)
def analyze_data(dataset: list) -> dict:
"""Process data in an isolated, resource-controlled environment."""
return {"processed": len(dataset), "status": "complete"}
When you run capsule run main.py, your code is compiled into a WebAssembly module and executed in a dedicated sandbox.
Documentation
Task Configuration Options
| Parameter | Description | Type | Default | Example |
|---|---|---|---|---|
name |
Task identifier | str |
function name | "process_data" |
compute |
CPU level: "LOW", "MEDIUM", "HIGH" |
str |
"MEDIUM" |
"HIGH" |
ram |
Memory limit | str |
unlimited | "512MB", "2GB" |
timeout |
Maximum execution time | str |
unlimited | "30s", "5m" |
max_retries |
Retry attempts on failure | int |
0 |
3 |
allowed_files |
Folders accessible in the sandbox | list |
[] |
["./data", "./output"] |
Compute Levels
- LOW: Minimal allocation for lightweight tasks
- MEDIUM: Balanced resources for typical workloads
- HIGH: Maximum fuel for compute-intensive operations
- CUSTOM: Specify exact fuel value (e.g.,
compute="1000000")
HTTP Client
Standard requests library isn't compatible with WASM. Use Capsule's HTTP client:
from capsule import task
from capsule.http import get, post
@task(name="fetch", compute="MEDIUM", timeout="30s")
def main() -> dict:
response = get("https://api.example.com/data")
return {"status": response.status_code, "ok": response.ok()}
File Access
The entry point task (main) has access to the entire project directory. Sub-tasks have no filesystem access by default and must declare allowed_files to access specific paths.
Python's standard file operations work normally. Use open(), os, pathlib, or any file manipulation library:
from capsule import task
@task(name="restricted_writer", allowed_files=["./output"]) # Sub-task with limited access
def restricted_writer() -> None:
with open("./output/result.txt", "w") as f:
f.write("result")
@task(name="main") # Has access to entire project
def main() -> str:
restricted_writer()
Compatibility
✅ Supported:
- Pure Python packages and standard library
json,math,re,datetime,collections, etc.
⚠️ Not yet supported:
- Packages with C extensions (e.g
numpy,pandas)
Links
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
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 capsule_run-0.3.1.tar.gz.
File metadata
- Download URL: capsule_run-0.3.1.tar.gz
- Upload date:
- Size: 83.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6d9d3dbb53453b07c28b5f45ceaccd7be9973f4bbdc948df161de55008e2f26d
|
|
| MD5 |
8e9009210680d004ba4766da94d715e4
|
|
| BLAKE2b-256 |
cb532500c84071b95614ed8c804e83c999d459634b4419b3c9c66f1cb234d64c
|
File details
Details for the file capsule_run-0.3.1-py3-none-win_amd64.whl.
File metadata
- Download URL: capsule_run-0.3.1-py3-none-win_amd64.whl
- Upload date:
- Size: 8.1 MB
- Tags: Python 3, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e97d96c32f9b0873a0c248de6e5c7a5d22c187aef7c43b51a2da58a0240a751f
|
|
| MD5 |
aad359c3665f5cfa4d6c24ae30a5a483
|
|
| BLAKE2b-256 |
2e110d5c2859a151f2ed4b8e63f9938a86311299941f1123c1a65ac46fcedbbf
|
File details
Details for the file capsule_run-0.3.1-py3-none-manylinux_2_39_x86_64.whl.
File metadata
- Download URL: capsule_run-0.3.1-py3-none-manylinux_2_39_x86_64.whl
- Upload date:
- Size: 8.5 MB
- Tags: Python 3, manylinux: glibc 2.39+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2611ad3dc174615c2bba8a1ceb1d6cb1d055fa8e81e99f36a993daf25924899e
|
|
| MD5 |
4c9d2e86680ef97fbde76c5d9c842223
|
|
| BLAKE2b-256 |
d13f9518ead8f00774a7bda3da72c210683f054a01cf75531af07b253b490de1
|
File details
Details for the file capsule_run-0.3.1-py3-none-macosx_11_0_arm64.whl.
File metadata
- Download URL: capsule_run-0.3.1-py3-none-macosx_11_0_arm64.whl
- Upload date:
- Size: 7.7 MB
- Tags: Python 3, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
da19d1f5bf4a7fa2c2eddacd9932b8359de49858662ebcb32a010645e3edd4e2
|
|
| MD5 |
f89ed79d3a8098a3071ac46bb948a5a1
|
|
| BLAKE2b-256 |
e71a5d6caf78585d6eff5197d7aef885d8eb9e3d8740d92c660d00b9593a4a54
|