| Crates.io | capsule-core |
| lib.rs | capsule-core |
| version | 0.2.2 |
| created_at | 2026-01-04 15:43:32.311949+00 |
| updated_at | 2026-01-04 17:42:43.610218+00 |
| description | Core library for Capsule - WASM runtime for AI agent isolation |
| homepage | |
| repository | https://github.com/mavdol/capsule |
| max_upload_size | |
| id | 2022081 |
| size | 304,439 |
A secure, durable runtime for agentic workflows
Getting Started • Documentation • Contributing
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:
This enables safe task-level execution of untrusted code within AI agent systems.
Capsule leverages Wasm to create secure, isolated execution environments.
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."""
# Your code runs safely in a Wasm sandbox
return {"processed": len(dataset), "status": "complete"}
Capsule now supports TypeScript and JavaScript with the task() wrapper function. This offers compatibility with the entire JavaScript ecosystem.
import { task } from "@capsule-run/sdk";
export const analyzeData = task({
name: "analyze_data",
compute: "MEDIUM",
ram: "512MB",
timeout: "30s",
maxRetries: 1
}, (dataset: number[]): object => {
// Your code runs safely in a Wasm sandbox
return { processed: dataset.length, status: "complete" };
});
// The "main" task is required as the entrypoint
export const main = task({
name: "main",
compute: "HIGH"
}, () => {
return analyzeData([1, 2, 3, 4, 5]);
});
[!NOTE] TypeScript/JavaScript projects require a task named
"main"as the entrypoint.
When you run capsule run main.py (or main.ts), your code is compiled into a WebAssembly module and executed in a dedicated sandbox to isolate tasks.
Each task operates within its own sandbox with configurable resource limits, ensuring that failures are contained and don't cascade to other parts of your workflow. The host system controls every aspect of execution, from CPU allocation via Wasm fuel metering to memory constraints and timeout enforcement.
pip install capsule-run
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
npm install -g @capsule-run/cli
npm install @capsule-run/sdk
Create hello.ts:
import { task } from "@capsule-run/sdk";
export const main = task({
name: "main",
compute: "LOW",
ram: "64MB"
}, (): string => {
return "Hello from Capsule!";
});
Run it:
capsule run hello.ts
[!TIP] Use
--verboseto display real-time task execution details.
Configure your tasks with these parameters:
| Parameter | Type | Description | Example |
|---|---|---|---|
name |
str |
Task identifier (defaults to function name) | "process_data" |
compute |
str |
CPU allocation level: "LOW", "MEDIUM", or "HIGH" |
"MEDIUM" |
ram |
str |
Memory limit for the task | "512MB", "2GB" |
timeout |
str |
Maximum execution time | "30s", "5m", "1h" |
max_retries |
int |
Number of retry attempts on failure (default: 1) | 3 |
Capsule controls CPU usage through WebAssembly's fuel mechanism, which meters instruction execution. The compute level determines how much fuel your task receives.
compute="1000000") for precise control over execution limits.The standard Python requests library and socket-based networking aren't natively compatible with WebAssembly's sandboxed I/O model. Capsule provides its own HTTP client that works within the Wasm environment:
from capsule import task
from capsule.http import get, post, put, delete
@task(name="http_example", compute="MEDIUM", timeout="30s")
def main() -> dict:
"""Example demonstrating HTTP client usage within a task."""
# GET request
response = get("https://api.example.com/data")
# POST with JSON body
response = post("https://api.example.com/submit", json={"key": "value"})
# Response methods
is_ok = response.ok() # Returns True if status code is 2xx
status = response.status_code # Get the HTTP status code
data = response.json() # Parse response as JSON
text = response.text() # Get response as text
return {"status": status, "success": is_ok}
Capsule also provides an HTTP client for TypeScript/JavaScript via @capsule-run/sdk. However, standard libraries like fetch already compatible, so you can use whichever approach you prefer.
[!NOTE] TypeScript/JavaScript has broader compatibility than Python since it doesn't rely on native bindings.
Python: Pure Python packages and standard library modules work. Packages with C extensions (numpy, pandas) are not yet supported.
TypeScript/JavaScript: npm packages and ES modules work. Node.js built-ins (fs, path, os) are not available in the sandbox.
Contributions are welcome!
Prerequisites: Rust (latest stable), Python 3.13+, Node.js 22+
git clone https://github.com/mavdol/capsule.git
cd capsule
# Build and install CLI
cargo install --path crates/capsule-cli
# Python SDK (editable install)
pip install -e crates/capsule-sdk/python
# TypeScript SDK (link for local dev)
cd crates/capsule-sdk/javascript
npm install && npm run build && npm link
# Then in your project: npm link @capsule-run/sdk
git checkout -b feature/amazing-featurecargo testNeed help? Open an issue
Capsule builds on these open source projects:
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.