Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ Run it:
capsule run hello.ts
```

> [!TIP]
> Use `--verbose` to display real-time task execution details.

## Documentation

Expand Down Expand Up @@ -187,13 +189,13 @@ Capsule also provides an HTTP client for TypeScript/JavaScript via `@capsule-run

## Compatibility

> [!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.

> [!NOTE]
> TypeScript/JavaScript has broader compatibility than Python since it doesn't rely on native bindings.

## Contributing

Contributions are welcome!
Expand Down
4 changes: 2 additions & 2 deletions crates/capsule-cli/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion crates/capsule-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
[package]
name = "capsule-run"
version = "0.2.1"
version = "0.2.2"
edition = "2024"
description = "Secure WASM runtime to isolate and manage AI agent tasks"
license = "Apache-2.0"
repository = "https://github.com/mavdol/capsule"
keywords = ["webassembly", "sandbox", "isolation", "llm", "ai"]
categories = ["command-line-utilities", "wasm"]
readme = "../../README.md"

[[bin]]
name = "capsule"
Expand Down
104 changes: 104 additions & 0 deletions crates/capsule-cli/docs/README-pypi.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# 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

```bash
pip install capsule-run
```

## Quick Start

Create `hello.py`:

```python
from capsule import task

@task(name="main", compute="LOW", ram="64MB")
def main() -> str:
return "Hello from Capsule!"
```

Run it:

```bash
capsule run hello.py
```

## How It Works

Simply annotate your Python functions with the `@task` decorator:

```python
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 | Type | Description | Example |
|-----------|------|-------------|---------|
| `name` | `str` | Task identifier | `"process_data"` |
| `compute` | `str` | CPU level: `"LOW"`, `"MEDIUM"`, `"HIGH"` | `"MEDIUM"` |
| `ram` | `str` | Memory limit | `"512MB"`, `"2GB"` |
| `timeout` | `str` | Maximum execution time | `"30s"`, `"5m"` |
| `max_retries` | `int` | Retry attempts on failure | `3` |

### 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:

```python
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()}
```

## 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

- [GitHub](https://github.com/mavdol/capsule)
- [Issues](https://github.com/mavdol/capsule/issues)

## License

Apache-2.0
108 changes: 108 additions & 0 deletions crates/capsule-cli/npm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# capsule

**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

```bash
npm install -g @capsule-run/cli
npm install @capsule-run/sdk
```

## Quick Start

Create `hello.ts`:

```typescript
import { task } from "@capsule-run/sdk";

export const main = task({
name: "main",
compute: "LOW",
ram: "64MB"
}, (): string => {
return "Hello from Capsule!";
});
```

Run it:

```bash
capsule run hello.ts
```

## How It Works

Simply use a wrapper function to define your tasks:

```typescript
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]);
});
```

When you run `capsule run main.ts`, your code is compiled into a WebAssembly module and executed in a dedicated sandbox.

## Documentation

### Task Configuration Options

| Parameter | Type | Description | Example |
|-----------|------|-------------|---------|
| `name` | `string` | Task identifier | `"process_data"` |
| `compute` | `string` | CPU level: `"LOW"`, `"MEDIUM"`, `"HIGH"` | `"MEDIUM"` |
| `ram` | `string` | Memory limit | `"512MB"`, `"2GB"` |
| `timeout` | `string` or `number` | Maximum execution time | `"30s"`, `"5m"` |
| `maxRetries` | `number` | Retry attempts on failure | `3` |

### 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"`)

## Compatibility

✅ **Supported:**
- npm packages and ES modules work

⚠️ **Not yet supported:**
- Node.js built-ins (`fs`, `path`, `os`) are not available in the sandbox

## Links

- [GitHub](https://github.com/mavdol/capsule)
- [Issues](https://github.com/mavdol/capsule/issues)

## License

Apache-2.0
51 changes: 51 additions & 0 deletions crates/capsule-cli/npm/bin/capsule.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env node

const { spawnSync } = require("child_process");
const path = require("path");
const fs = require("fs");

const PLATFORMS = {
"darwin-arm64": "@capsule-run/cli-darwin-arm64",
"darwin-x64": "@capsule-run/cli-darwin-x64",
"linux-x64": "@capsule-run/cli-linux-x64",
"win32-x64": "@capsule-run/cli-win32-x64",
};

function getPlatformPackage() {
const key = `${process.platform}-${process.arch}`;
return PLATFORMS[key];
}

function findBinary() {
const pkg = getPlatformPackage();
if (!pkg) {
console.error(`Unsupported platform: ${process.platform}-${process.arch}`);
process.exit(1);
}

try {
const pkgPath = require.resolve(`${pkg}/package.json`);
const pkgDir = path.dirname(pkgPath);
const binary = process.platform === "win32" ? "capsule.exe" : "capsule";
const binaryPath = path.join(pkgDir, binary);

if (fs.existsSync(binaryPath)) {
return binaryPath;
}
} catch {
// Package not found
}

console.error(`Could not find capsule binary for ${process.platform}-${process.arch}`);
console.error(`Please ensure @capsule-run/cli is installed correctly.`);
process.exit(1);
}

const result = spawnSync(findBinary(), process.argv.slice(2), { stdio: "inherit" });

if (result.error) {
console.error(result.error.message);
process.exit(1);
}

process.exit(result.status ?? 1);
27 changes: 18 additions & 9 deletions crates/capsule-cli/npm/package.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,37 @@
{
"name": "@capsule-run/cli",
"version": "0.2.1",
"version": "0.2.2",
"description": "Secure WASM runtime to isolate and manage AI agent tasks",
"bin": {
"capsule": "./bin/capsule.js"
},
"files": [
"bin/"
],
"keywords": [
"webassembly",
"cli",
"sandbox",
"agent",
"agents",
"isolation",
"security",
"llm"
"llm",
"ai"
],
"license": "Apache-2.0",
"repository": {
"type": "git",
"url": "https://github.com/mavdol/capsule.git"
},
"homepage": "https://github.com/mavdol/capsule",
"publishConfig": {
"access": "public"
},
"engines": {
"node": ">=18"
},
"optionalDependencies": {
"@capsule-run/cli-darwin-arm64": "0.2.1",
"@capsule-run/cli-darwin-x64": "0.2.1",
"@capsule-run/cli-linux-x64": "0.2.1",
"@capsule-run/cli-win32-x64": "0.2.1"
"@capsule-run/cli-darwin-arm64": "0.2.2",
"@capsule-run/cli-darwin-x64": "0.2.2",
"@capsule-run/cli-linux-x64": "0.2.2",
"@capsule-run/cli-win32-x64": "0.2.2"
}
}
3 changes: 2 additions & 1 deletion crates/capsule-cli/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ build-backend = "maturin"

[project]
name = "capsule-run"
version = "0.2.1"
version = "0.2.2"
description = "Secure WASM runtime to isolate and manage AI agent tasks"
readme = "docs/README-pypi.md"
license = {text = "Apache-2.0"}
requires-python = ">=3.8"
authors = [
Expand Down
2 changes: 1 addition & 1 deletion crates/capsule-core/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading