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.0.tar.gz (79.8 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.0-py3-none-win_amd64.whl (8.1 MB view details)

Uploaded Python 3Windows x86-64

capsule_run-0.3.0-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.0-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.0.tar.gz.

File metadata

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

File hashes

Hashes for capsule_run-0.3.0.tar.gz
Algorithm Hash digest
SHA256 fbd3105b4d9c5a0311ef0c032da062986f14bca8ccd69946e47de100599b7b23
MD5 bc6bdff712a01a4e0128a162ce79e238
BLAKE2b-256 39d44bf3f7930be86bc03ed88e40bc08fb69ea5299f90a7a9bb37511a0af6d03

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for capsule_run-0.3.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 6999a231bf8c83e31e0ad2191430dd0fcf00f9515370ee91dc8f04d1a4da46db
MD5 f04229d9714ffa8b0e88a185aa9f05ad
BLAKE2b-256 340177622e407fc5d1c5e842999ae5d4d8172d48bc5b647fa766c15966f16c50

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for capsule_run-0.3.0-py3-none-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 f7fff22a3f6feb04957086e60a97d3c42f72d3267d2ad5c0064c6ec91856cbbd
MD5 1db31c48dcf84649e7e3d25de1969ace
BLAKE2b-256 9618155bb536a3899805ba61c47842fc9961b12722bd945a396d5e382e95517d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for capsule_run-0.3.0-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ee165df2a398253215efcc67bf653563cee782ac30cc065eea5f79cc68816d83
MD5 7a875adf9fcc2218524a994fe503634f
BLAKE2b-256 0896e703dac0fa223d2485b49f1a896df316ea1638d9572cf866d9940266ab4f

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