@capsule-run/cli 0.5.2 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +50 -2
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ npm install -g @capsule-run/cli
|
|
|
20
20
|
npm install @capsule-run/sdk
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
-
##
|
|
23
|
+
## Getting started
|
|
24
24
|
|
|
25
25
|
Create `hello.ts`:
|
|
26
26
|
|
|
@@ -44,6 +44,35 @@ capsule run hello.ts
|
|
|
44
44
|
|
|
45
45
|
> Use `--verbose` to display real-time task execution details.
|
|
46
46
|
|
|
47
|
+
## Integrate Into an Existing Project
|
|
48
|
+
|
|
49
|
+
The `run()` function lets you execute tasks programmatically from your application code, no CLI needed.
|
|
50
|
+
|
|
51
|
+
> You need `@capsule-run/cli` in your dependencies to use the `runner` functions in TypeScript.
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
import { run } from '@capsule-run/sdk/runner';
|
|
55
|
+
|
|
56
|
+
const result = await run({
|
|
57
|
+
file: './capsule.ts',
|
|
58
|
+
args: ['code to execute']
|
|
59
|
+
});
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Create `capsule.ts`:
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
import { task } from "@capsule-run/sdk";
|
|
66
|
+
|
|
67
|
+
export const main = task({
|
|
68
|
+
name: "main",
|
|
69
|
+
compute: "LOW",
|
|
70
|
+
ram: "64MB"
|
|
71
|
+
}, (code: string): string => {
|
|
72
|
+
return eval(code);
|
|
73
|
+
});
|
|
74
|
+
```
|
|
75
|
+
|
|
47
76
|
## How It Works
|
|
48
77
|
|
|
49
78
|
Simply use a wrapper function to define your tasks:
|
|
@@ -108,11 +137,12 @@ Every task returns a structured JSON envelope containing both the result and exe
|
|
|
108
137
|
| Parameter | Description | Type | Default | Example |
|
|
109
138
|
|-----------|-------------|------|---------|---------|
|
|
110
139
|
| `name` | Task identifier | `string` | *required* | `"process_data"` |
|
|
111
|
-
| `compute` | CPU level: `"LOW"`, `"MEDIUM"
|
|
140
|
+
| `compute` | CPU level: `"LOW"`, `"MEDIUM`", `"HIGH"` | `string` | `"MEDIUM"` | `"HIGH"` |
|
|
112
141
|
| `ram` | Memory limit | `string` | unlimited | `"512MB"`, `"2GB"` |
|
|
113
142
|
| `timeout` | Maximum execution time | `string` or `number` | unlimited | `"30s"`, `"5m"`, `30000` (ms) |
|
|
114
143
|
| `maxRetries` | Retry attempts on failure | `number` | `0` | `3` |
|
|
115
144
|
| `allowedFiles` | Folders accessible in the sandbox | `string[]` | `[]` | `["./data", "./output"]` |
|
|
145
|
+
| `allowedHosts` | Domains accessible in the sandbox | `string[]` | `["*"]` | `["api.openai.com", "*.anthropic.com"]` |
|
|
116
146
|
| `envVariables` | Environment variables accessible in the sandbox | `string[]` | `[]` | `["API_KEY"]` |
|
|
117
147
|
|
|
118
148
|
### Compute Levels
|
|
@@ -163,6 +193,24 @@ export const main = task({ name: "main", allowedFiles: ["./data"] }, async () =>
|
|
|
163
193
|
});
|
|
164
194
|
```
|
|
165
195
|
|
|
196
|
+
### Network Access
|
|
197
|
+
|
|
198
|
+
Tasks can make HTTP requests to domains specified in `allowedHosts`. By default, all outbound requests are allowed (`[\"*\"]`). Restrict access by providing a whitelist of domains.
|
|
199
|
+
|
|
200
|
+
> Wildcards are supported: `*.example.com` matches all subdomains of `example.com`.
|
|
201
|
+
|
|
202
|
+
```typescript
|
|
203
|
+
import { task } from "@capsule-run/sdk";
|
|
204
|
+
|
|
205
|
+
export const main = task({
|
|
206
|
+
name: "main",
|
|
207
|
+
allowedHosts: ["api.openai.com", "*.anthropic.com"]
|
|
208
|
+
}, async () => {
|
|
209
|
+
const response = await fetch("https://api.openai.com/v1/models");
|
|
210
|
+
return response.json();
|
|
211
|
+
});
|
|
212
|
+
```
|
|
213
|
+
|
|
166
214
|
### Environment Variables
|
|
167
215
|
|
|
168
216
|
Tasks can access environment variables to read configuration, API keys, or other runtime settings. Use the standard `process.env`:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capsule-run/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Secure WASM runtime to isolate and manage AI agent tasks",
|
|
5
5
|
"bin": {
|
|
6
6
|
"capsule": "./bin/capsule.js"
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
"node": ">=18"
|
|
30
30
|
},
|
|
31
31
|
"optionalDependencies": {
|
|
32
|
-
"@capsule-run/cli-darwin-arm64": "0.
|
|
33
|
-
"@capsule-run/cli-darwin-x64": "0.
|
|
34
|
-
"@capsule-run/cli-linux-x64": "0.
|
|
35
|
-
"@capsule-run/cli-win32-x64": "0.
|
|
32
|
+
"@capsule-run/cli-darwin-arm64": "0.6.0",
|
|
33
|
+
"@capsule-run/cli-darwin-x64": "0.6.0",
|
|
34
|
+
"@capsule-run/cli-linux-x64": "0.6.0",
|
|
35
|
+
"@capsule-run/cli-win32-x64": "0.6.0"
|
|
36
36
|
}
|
|
37
37
|
}
|