Skip to main content

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


Download files

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

Source Distribution

capsule_run-0.3.2.tar.gz (83.2 kB view details)

Uploaded Source

Built Distributions

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

capsule_run-0.3.2-py3-none-win_amd64.whl (8.1 MB view details)

Uploaded Python 3Windows x86-64

capsule_run-0.3.2-py3-none-manylinux_2_39_x86_64.whl (8.5 MB view details)

Uploaded Python 3manylinux: glibc 2.39+ x86-64

capsule_run-0.3.2-py3-none-macosx_11_0_arm64.whl (7.7 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

File details

Details for the file capsule_run-0.3.2.tar.gz.

File metadata

  • Download URL: capsule_run-0.3.2.tar.gz
  • Upload date:
  • Size: 83.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.11.5

File hashes

Hashes for capsule_run-0.3.2.tar.gz
Algorithm Hash digest
SHA256 c614f8895325344ee280c8a13886b2f1ec28d6feff9f5e58107c71ba3147cda1
MD5 ed2e1a939abe96596de3a7a15b1243d8
BLAKE2b-256 180ac373f4c744b3143b13583c45480c5717ed5e459566e3d50fd5ed6680d975

See more details on using hashes here.

File details

Details for the file capsule_run-0.3.2-py3-none-win_amd64.whl.

File metadata

File hashes

Hashes for capsule_run-0.3.2-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 21a09e618bf7785cbd217ae65a7059a6aeec6b136ca0cce1e072514544fed388
MD5 85e8dae7a8149e32add60a5b18c954fc
BLAKE2b-256 69a29ea6a83d4595eba85f61c48c7c3f22624bace4ff378b810252b531ec649a

See more details on using hashes here.

File details

Details for the file capsule_run-0.3.2-py3-none-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for capsule_run-0.3.2-py3-none-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 87258af17736e69db67235464af3b5c8d96c0ba8298b242bc3dfe19ec4047825
MD5 0d3f917d6b2686db1a2184cd4d0d02b4
BLAKE2b-256 cd6a9985e93032e4bf27cd2e78081e2028318267e5cb41083eb0fd570df5f767

See more details on using hashes here.

File details

Details for the file capsule_run-0.3.2-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for capsule_run-0.3.2-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 661d642a3145b4209605ec96b2aada3f38899fb80d9fe01148b6a597e1c68aa3
MD5 72e3d290fbcb5f826789b414a02896d0
BLAKE2b-256 64469bbe1c00dd09c61520360297d112533fc7b3bcb875776102ce1684191a0c

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