@magpiecloud/mags 1.8.13 → 1.8.15
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 +95 -378
- package/bin/mags.js +196 -104
- package/index.js +6 -52
- package/package.json +22 -4
- package/API.md +0 -388
- package/Mags-API.postman_collection.json +0 -374
- package/QUICKSTART.md +0 -295
- package/deploy-page.sh +0 -171
- package/mags +0 -0
- package/mags.sh +0 -270
- package/nodejs/README.md +0 -197
- package/nodejs/bin/mags.js +0 -1146
- package/nodejs/index.js +0 -642
- package/nodejs/package.json +0 -42
- package/python/INTEGRATION.md +0 -800
- package/python/README.md +0 -161
- package/python/dist/magpie_mags-1.3.5-py3-none-any.whl +0 -0
- package/python/dist/magpie_mags-1.3.5.tar.gz +0 -0
- package/python/examples/demo.py +0 -181
- package/python/pyproject.toml +0 -39
- package/python/src/magpie_mags.egg-info/PKG-INFO +0 -182
- package/python/src/magpie_mags.egg-info/SOURCES.txt +0 -9
- package/python/src/magpie_mags.egg-info/dependency_links.txt +0 -1
- package/python/src/magpie_mags.egg-info/requires.txt +0 -1
- package/python/src/magpie_mags.egg-info/top_level.txt +0 -1
- package/python/src/mags/__init__.py +0 -6
- package/python/src/mags/client.py +0 -573
- package/python/test_sdk.py +0 -78
- package/skill.md +0 -153
- package/website/api.html +0 -1095
- package/website/claude-skill.html +0 -481
- package/website/cookbook/hn-marketing.html +0 -410
- package/website/cookbook/hn-marketing.sh +0 -42
- package/website/cookbook.html +0 -282
- package/website/env.js +0 -4
- package/website/index.html +0 -801
- package/website/llms.txt +0 -334
- package/website/login.html +0 -108
- package/website/mags.md +0 -210
- package/website/script.js +0 -453
- package/website/styles.css +0 -908
- package/website/tokens.html +0 -169
- package/website/usage.html +0 -185
package/README.md
CHANGED
|
@@ -1,17 +1,6 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @magpiecloud/mags
|
|
2
2
|
|
|
3
|
-
Execute scripts instantly on Magpie's microVM infrastructure. VMs boot in <100ms from a warm pool
|
|
4
|
-
|
|
5
|
-
## What is Mags?
|
|
6
|
-
|
|
7
|
-
Mags is a CLI and SDK for running scripts on ephemeral microVMs. Each execution gets its own isolated VM that:
|
|
8
|
-
|
|
9
|
-
- Boots in ~300ms (from warm pool)
|
|
10
|
-
- Supports optional S3-backed persistent workspaces (with `-p` flag)
|
|
11
|
-
- Syncs /root directory automatically when persistence is enabled
|
|
12
|
-
- Can expose public URLs for web services
|
|
13
|
-
- Provides SSH access through secure proxy
|
|
14
|
-
- Auto-sleeps when idle and wakes on request
|
|
3
|
+
Execute scripts instantly on Magpie's microVM infrastructure. VMs boot in <100ms from a warm pool.
|
|
15
4
|
|
|
16
5
|
## Installation
|
|
17
6
|
|
|
@@ -19,411 +8,176 @@ Mags is a CLI and SDK for running scripts on ephemeral microVMs. Each execution
|
|
|
19
8
|
npm install -g @magpiecloud/mags
|
|
20
9
|
```
|
|
21
10
|
|
|
22
|
-
##
|
|
11
|
+
## Quick Start
|
|
23
12
|
|
|
24
|
-
###
|
|
13
|
+
### 1. Login to Magpie
|
|
25
14
|
|
|
26
15
|
```bash
|
|
27
16
|
mags login
|
|
28
17
|
```
|
|
29
18
|
|
|
30
|
-
This
|
|
19
|
+
This will open your browser to create an API token. Paste the token when prompted, and it will be saved for future use.
|
|
31
20
|
|
|
32
|
-
###
|
|
21
|
+
### 2. Create a sandbox
|
|
33
22
|
|
|
34
23
|
```bash
|
|
35
|
-
mags
|
|
36
|
-
mags
|
|
37
|
-
mags
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
### Environment Variable (Alternative)
|
|
41
|
-
|
|
42
|
-
```bash
|
|
43
|
-
export MAGS_API_TOKEN="your-token-here"
|
|
24
|
+
mags new myproject # Local disk only
|
|
25
|
+
mags new myproject -p # With S3 persistence
|
|
26
|
+
mags ssh myproject
|
|
44
27
|
```
|
|
45
28
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
### Run a simple command
|
|
29
|
+
### 3. Or run a script
|
|
49
30
|
|
|
50
31
|
```bash
|
|
51
32
|
mags run 'echo Hello World'
|
|
52
33
|
```
|
|
53
34
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
```bash
|
|
57
|
-
# Create a new VM (local disk only)
|
|
58
|
-
mags new myproject
|
|
59
|
-
|
|
60
|
-
# Create with S3 data persistence
|
|
61
|
-
mags new myproject -p
|
|
62
|
-
|
|
63
|
-
# SSH into it
|
|
64
|
-
mags ssh myproject
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
### Run with a persistent workspace
|
|
68
|
-
|
|
69
|
-
Workspaces persist data between runs using S3 sync:
|
|
70
|
-
|
|
71
|
-
```bash
|
|
72
|
-
# First run - install dependencies
|
|
73
|
-
mags run -w myproject 'apk add python3 py3-pip && pip install requests'
|
|
74
|
-
|
|
75
|
-
# Second run - dependencies are still there
|
|
76
|
-
mags run -w myproject 'python3 -c "import requests; print(requests.__version__)"'
|
|
77
|
-
```
|
|
35
|
+
## Authentication
|
|
78
36
|
|
|
79
|
-
###
|
|
37
|
+
### Interactive Login (Recommended)
|
|
80
38
|
|
|
81
39
|
```bash
|
|
82
|
-
mags
|
|
83
|
-
# Returns: https://abc123.apps.magpiecloud.com
|
|
40
|
+
mags login
|
|
84
41
|
```
|
|
85
42
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
### Commands
|
|
89
|
-
|
|
90
|
-
| Command | Description |
|
|
91
|
-
|---------|-------------|
|
|
92
|
-
| `mags login` | Authenticate with Magpie (saves token locally) |
|
|
93
|
-
| `mags logout` | Remove saved credentials |
|
|
94
|
-
| `mags whoami` | Show current authentication status |
|
|
95
|
-
| `mags new <workspace> [-p]` | Create a VM sandbox (add `-p` for S3 persistence) |
|
|
96
|
-
| `mags run [options] <script>` | Execute a script on a microVM |
|
|
97
|
-
| `mags ssh <workspace>` | Open interactive SSH session to a VM |
|
|
98
|
-
| `mags status <job-id>` | Get job status |
|
|
99
|
-
| `mags logs <job-id>` | Get job logs |
|
|
100
|
-
| `mags list` | List recent jobs |
|
|
101
|
-
| `mags url <job-id> [port]` | Enable URL access for a job |
|
|
102
|
-
| `mags stop <job-id>` | Stop a running job |
|
|
103
|
-
| `mags set <name\|id> [options]` | Update VM settings (`--no-sleep`, `--sleep`) |
|
|
104
|
-
|
|
105
|
-
### Run Options
|
|
106
|
-
|
|
107
|
-
| Flag | Description | Default |
|
|
108
|
-
|------|-------------|---------|
|
|
109
|
-
| `-w, --workspace <id>` | Use persistent workspace (S3 sync) | auto-generated |
|
|
110
|
-
| `-p, --persistent` | Keep VM alive after script completes | false |
|
|
111
|
-
| `--url` | Enable public URL access (requires -p) | false |
|
|
112
|
-
| `--port <port>` | Port to expose for URL access | 8080 |
|
|
113
|
-
| `--no-sleep` | Keep VM always running, never auto-sleep (requires -p) | false |
|
|
114
|
-
| `--startup-command <cmd>` | Command to run when VM wakes from sleep | none |
|
|
115
|
-
|
|
116
|
-
## SSH Access
|
|
43
|
+
Opens the Magpie dashboard in your browser where you can create an API token. The token is saved to `~/.mags/config.json` and used automatically for all future commands.
|
|
117
44
|
|
|
118
|
-
|
|
45
|
+
### Other Auth Commands
|
|
119
46
|
|
|
120
47
|
```bash
|
|
121
|
-
mags
|
|
48
|
+
mags whoami # Check current authentication status
|
|
49
|
+
mags logout # Remove saved credentials
|
|
122
50
|
```
|
|
123
51
|
|
|
124
|
-
###
|
|
125
|
-
|
|
126
|
-
- **Secure proxy**: Connect via `api.magpiecloud.com:PORT` (agent IPs are hidden)
|
|
127
|
-
- **PTY support**: Full interactive terminal with colors and editors
|
|
128
|
-
- **Key-based auth**: Automatic SSH key management
|
|
129
|
-
- **Hostname**: VMs use `mags-vm` as hostname
|
|
52
|
+
### Environment Variable
|
|
130
53
|
|
|
131
|
-
|
|
54
|
+
You can also set the token via environment variable (overrides saved config):
|
|
132
55
|
|
|
133
56
|
```bash
|
|
134
|
-
|
|
135
|
-
Connecting to api.magpiecloud.com:40006...
|
|
136
|
-
(Use Ctrl+D or 'exit' to disconnect)
|
|
137
|
-
|
|
138
|
-
mags-vm:~# ls
|
|
139
|
-
index.html test.txt
|
|
140
|
-
|
|
141
|
-
mags-vm:~# python3 --version
|
|
142
|
-
Python 3.11.6
|
|
143
|
-
|
|
144
|
-
mags-vm:~# exit
|
|
57
|
+
export MAGS_API_TOKEN="your-token-here"
|
|
145
58
|
```
|
|
146
59
|
|
|
147
|
-
##
|
|
148
|
-
|
|
149
|
-
### How It Works
|
|
60
|
+
## CLI Commands
|
|
150
61
|
|
|
151
|
-
|
|
62
|
+
```bash
|
|
63
|
+
# Create a sandbox (local disk)
|
|
64
|
+
mags new myproject
|
|
152
65
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
3. Syncs your `/root` directory to S3 every 30 seconds
|
|
156
|
-
4. Restores your files when you reconnect
|
|
66
|
+
# Create with S3 persistence
|
|
67
|
+
mags new myproject -p
|
|
157
68
|
|
|
158
|
-
|
|
69
|
+
# SSH into it
|
|
70
|
+
mags ssh myproject
|
|
159
71
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
- Installed packages and dependencies
|
|
163
|
-
- Configuration files and dotfiles
|
|
72
|
+
# Run a simple command
|
|
73
|
+
mags run 'echo Hello'
|
|
164
74
|
|
|
165
|
-
|
|
75
|
+
# With persistent workspace (S3 sync)
|
|
76
|
+
mags run -w my-project 'apk add nodejs && node --version'
|
|
166
77
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
| While running | Auto-sync every 30 seconds |
|
|
170
|
-
| On stop | Full sync before VM terminates |
|
|
171
|
-
| On wake | Previous state restored instantly |
|
|
78
|
+
# Persistent VM with public URL
|
|
79
|
+
mags run -w webapp -p --url 'python3 -m http.server 8080'
|
|
172
80
|
|
|
173
|
-
|
|
81
|
+
# With startup command (for auto-wake)
|
|
82
|
+
mags run -w webapp -p --url --startup-command 'npm start' 'npm install && npm start'
|
|
174
83
|
|
|
175
|
-
|
|
84
|
+
# Custom port
|
|
85
|
+
mags run -w webapp -p --url --port 3000 'npm start'
|
|
176
86
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
mags
|
|
87
|
+
# Enable URL for existing job
|
|
88
|
+
mags url <job-id>
|
|
89
|
+
mags url <job-id> 8080
|
|
180
90
|
|
|
181
|
-
#
|
|
182
|
-
mags
|
|
91
|
+
# Other commands
|
|
92
|
+
mags status <job-id>
|
|
93
|
+
mags logs <job-id>
|
|
94
|
+
mags list
|
|
95
|
+
mags stop <job-id>
|
|
183
96
|
|
|
184
|
-
#
|
|
185
|
-
mags
|
|
97
|
+
# Install Claude Code skill
|
|
98
|
+
mags setup-claude
|
|
186
99
|
```
|
|
187
100
|
|
|
188
|
-
|
|
101
|
+
## Claude Code Integration
|
|
189
102
|
|
|
190
|
-
|
|
191
|
-
# Create a workspace with dependencies
|
|
192
|
-
mags run -w ml-project 'apk add python3 py3-pip && pip install numpy pandas scikit-learn'
|
|
193
|
-
|
|
194
|
-
# Run scripts using the workspace
|
|
195
|
-
mags run -w ml-project 'python3 train.py'
|
|
103
|
+
Install the Mags skill for Claude Code to run scripts directly from Claude:
|
|
196
104
|
|
|
197
|
-
|
|
198
|
-
mags
|
|
105
|
+
```bash
|
|
106
|
+
mags setup-claude
|
|
199
107
|
```
|
|
200
108
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
mags run -p --url 'python3 -m http.server 8080'
|
|
109
|
+
This lets you use natural language commands like:
|
|
110
|
+
- `/mags run echo Hello World`
|
|
111
|
+
- `/mags create a python environment with numpy and pandas`
|
|
112
|
+
- `/mags run a flask server and give me the public URL`
|
|
206
113
|
|
|
207
|
-
|
|
208
|
-
mags run -w myapp -p --url --port 3000 'npm install && npm start'
|
|
114
|
+
See [mags.run/claude-skill.html](https://mags.run/claude-skill.html) for full documentation.
|
|
209
115
|
|
|
210
|
-
|
|
211
|
-
mags run -w flask-app -p --url 'pip install flask && python app.py'
|
|
116
|
+
## CLI Flags
|
|
212
117
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
118
|
+
| Flag | Description | Default |
|
|
119
|
+
|------|-------------|---------|
|
|
120
|
+
| `-w, --workspace` | Workspace ID for persistent storage | auto |
|
|
121
|
+
| `-p, --persistent` | Keep VM alive for URL/SSH access | false |
|
|
122
|
+
| `--url` | Enable public URL access (requires -p) | false |
|
|
123
|
+
| `--port` | Port to expose for URL access | 8080 |
|
|
124
|
+
| `--startup-command` | Command when VM wakes from sleep | none |
|
|
216
125
|
|
|
217
|
-
|
|
126
|
+
## SSH Access
|
|
218
127
|
|
|
219
|
-
|
|
128
|
+
Connect to any running VM:
|
|
220
129
|
|
|
221
130
|
```bash
|
|
222
|
-
|
|
223
|
-
mags run -w my-api -p --no-sleep --url --port 3000 'npm start'
|
|
224
|
-
|
|
225
|
-
# Always-on background worker
|
|
226
|
-
mags run -w worker -p --no-sleep 'python worker.py'
|
|
131
|
+
mags ssh myproject
|
|
227
132
|
```
|
|
228
133
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
134
|
+
Features:
|
|
135
|
+
- Connects via secure proxy (`api.magpiecloud.com:PORT`)
|
|
136
|
+
- Full PTY support for interactive terminals
|
|
137
|
+
- Automatic SSH key management
|
|
138
|
+
- Hostname: `mags-vm`
|
|
232
139
|
|
|
233
|
-
|
|
234
|
-
# Create a dev environment (local disk)
|
|
235
|
-
mags new dev-env
|
|
140
|
+
## Workspaces & Persistence
|
|
236
141
|
|
|
237
|
-
|
|
238
|
-
|
|
142
|
+
When using persistent mode (`-p`), your `/root` directory syncs to S3:
|
|
143
|
+
- **Auto-sync**: Every 30 seconds while running
|
|
144
|
+
- **On stop**: Full sync before VM terminates
|
|
145
|
+
- **On wake**: Previous state restored
|
|
239
146
|
|
|
240
|
-
|
|
241
|
-
mags-vm:~# apk add git nodejs npm
|
|
242
|
-
mags-vm:~# git clone https://github.com/user/repo
|
|
243
|
-
mags-vm:~# cd repo && npm install
|
|
244
|
-
mags-vm:~# npm run dev
|
|
245
|
-
```
|
|
147
|
+
Without `-p`, data lives on local disk only and is cleaned up when the VM is destroyed.
|
|
246
148
|
|
|
247
149
|
## Node.js SDK
|
|
248
150
|
|
|
249
|
-
For programmatic access, use the SDK:
|
|
250
|
-
|
|
251
151
|
```javascript
|
|
252
152
|
const Mags = require('@magpiecloud/mags');
|
|
253
153
|
|
|
254
154
|
const mags = new Mags({
|
|
255
155
|
apiToken: process.env.MAGS_API_TOKEN
|
|
256
156
|
});
|
|
257
|
-
```
|
|
258
|
-
|
|
259
|
-
### SDK Methods
|
|
260
|
-
|
|
261
|
-
#### Jobs
|
|
262
|
-
|
|
263
|
-
| Method | Description |
|
|
264
|
-
|--------|-------------|
|
|
265
|
-
| `run(script, options)` | Submit a job. Options: `name`, `workspaceId`, `baseWorkspaceId`, `persistent`, `noSleep`, `ephemeral`, `startupCommand`, `environment`, `fileIds`, `diskGb` |
|
|
266
|
-
| `runAndWait(script, options)` | Submit and block until done. Extra options: `timeout`, `pollInterval` |
|
|
267
|
-
| `new(name, options)` | Create a VM sandbox and wait until running. Options: `persistent`, `baseWorkspaceId`, `diskGb`, `timeout` |
|
|
268
|
-
| `status(requestId)` | Get job status |
|
|
269
|
-
| `logs(requestId)` | Get job logs |
|
|
270
|
-
| `list({page, pageSize})` | List recent jobs (paginated) |
|
|
271
|
-
| `findJob(nameOrId)` | Find job by name, workspace ID, or request ID |
|
|
272
|
-
| `updateJob(requestId, {startupCommand, noSleep})` | Update job settings |
|
|
273
|
-
| `stop(nameOrId)` | Stop a job (accepts name, workspace ID, or request ID) |
|
|
274
|
-
| `exec(nameOrId, command, {timeout})` | Execute a command on a running/sleeping VM via SSH |
|
|
275
|
-
| `sync(requestId)` | Sync workspace to S3 without stopping |
|
|
276
|
-
| `resize(workspace, diskGb)` | Resize workspace disk (stops VM, creates new one) |
|
|
277
|
-
| `usage({windowDays})` | Get aggregated usage summary |
|
|
278
|
-
|
|
279
|
-
#### URL & Access
|
|
280
|
-
|
|
281
|
-
| Method | Description |
|
|
282
|
-
|--------|-------------|
|
|
283
|
-
| `enableAccess(requestId, port)` | Enable SSH (port 22) or HTTP access (default 8080) |
|
|
284
|
-
| `url(nameOrId, port)` | Enable public URL and return the full URL |
|
|
285
|
-
| `urlAliasCreate(subdomain, workspaceId, domain)` | Create a stable URL alias for a workspace |
|
|
286
|
-
| `urlAliasList()` | List all URL aliases |
|
|
287
|
-
| `urlAliasDelete(subdomain)` | Delete a URL alias |
|
|
288
|
-
|
|
289
|
-
#### Workspaces
|
|
290
|
-
|
|
291
|
-
| Method | Description |
|
|
292
|
-
|--------|-------------|
|
|
293
|
-
| `listWorkspaces()` | List all workspaces |
|
|
294
|
-
| `deleteWorkspace(workspaceId)` | Delete a workspace and its S3 data |
|
|
295
|
-
|
|
296
|
-
#### Files
|
|
297
|
-
|
|
298
|
-
| Method | Description |
|
|
299
|
-
|--------|-------------|
|
|
300
|
-
| `uploadFiles(filePaths)` | Upload local files, returns array of file IDs |
|
|
301
|
-
|
|
302
|
-
#### Cron Jobs
|
|
303
|
-
|
|
304
|
-
| Method | Description |
|
|
305
|
-
|--------|-------------|
|
|
306
|
-
| `cronCreate({name, cronExpression, script, workspaceId, environment, persistent})` | Create a scheduled job |
|
|
307
|
-
| `cronList()` | List all cron jobs |
|
|
308
|
-
| `cronGet(id)` | Get a cron job |
|
|
309
|
-
| `cronUpdate(id, updates)` | Update a cron job |
|
|
310
|
-
| `cronDelete(id)` | Delete a cron job |
|
|
311
|
-
|
|
312
|
-
### SDK Examples
|
|
313
157
|
|
|
314
|
-
```javascript
|
|
315
158
|
// Run and wait for completion
|
|
316
159
|
const result = await mags.runAndWait('echo Hello World');
|
|
317
160
|
console.log(result.logs);
|
|
318
161
|
|
|
319
|
-
//
|
|
320
|
-
await mags.
|
|
321
|
-
|
|
322
|
-
// Create a sandbox with S3 persistence
|
|
323
|
-
await mags.new('myproject', { persistent: true });
|
|
324
|
-
|
|
325
|
-
// Execute command on existing VM
|
|
326
|
-
const { output } = await mags.exec('myproject', 'ls -la /root');
|
|
327
|
-
console.log(output);
|
|
328
|
-
|
|
329
|
-
// Run with workspace and options
|
|
330
|
-
const job = await mags.run('python script.py', {
|
|
162
|
+
// Run with workspace
|
|
163
|
+
const { requestId } = await mags.run('python script.py', {
|
|
331
164
|
workspaceId: 'myproject',
|
|
332
|
-
persistent: true
|
|
333
|
-
diskGb: 5,
|
|
334
|
-
startupCommand: 'python server.py'
|
|
335
|
-
});
|
|
336
|
-
|
|
337
|
-
// Always-on VM (never auto-sleeps)
|
|
338
|
-
await mags.run('node server.js', {
|
|
339
|
-
workspaceId: 'my-api',
|
|
340
|
-
persistent: true,
|
|
341
|
-
noSleep: true
|
|
165
|
+
persistent: true
|
|
342
166
|
});
|
|
343
167
|
|
|
344
|
-
//
|
|
345
|
-
const
|
|
346
|
-
console.log(url); // https://abc123.apps.magpiecloud.com
|
|
347
|
-
|
|
348
|
-
// Create stable URL alias
|
|
349
|
-
await mags.urlAliasCreate('my-app', 'my-api');
|
|
350
|
-
|
|
351
|
-
// Resize workspace disk
|
|
352
|
-
await mags.resize('myproject', 10); // 10GB
|
|
353
|
-
|
|
354
|
-
// Stop a job by name
|
|
355
|
-
await mags.stop('myproject');
|
|
356
|
-
```
|
|
357
|
-
|
|
358
|
-
## API Endpoints
|
|
359
|
-
|
|
360
|
-
For direct API access:
|
|
168
|
+
// Get status
|
|
169
|
+
const status = await mags.status(requestId);
|
|
361
170
|
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
| `/api/v1/mags-jobs` | POST | Submit a new job |
|
|
365
|
-
| `/api/v1/mags-jobs` | GET | List jobs (paginated) |
|
|
366
|
-
| `/api/v1/mags-jobs/{id}/status` | GET | Get job status |
|
|
367
|
-
| `/api/v1/mags-jobs/{id}/logs` | GET | Get job logs |
|
|
368
|
-
| `/api/v1/mags-jobs/{id}/access` | POST | Enable SSH/URL access |
|
|
369
|
-
| `/api/v1/mags-jobs/{id}` | PATCH | Update job settings |
|
|
171
|
+
// Enable URL access
|
|
172
|
+
await mags.enableUrl(requestId, 8080);
|
|
370
173
|
|
|
371
|
-
|
|
174
|
+
// List jobs
|
|
175
|
+
const jobs = await mags.list({ page: 1, pageSize: 10 });
|
|
372
176
|
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
-H "Authorization: Bearer $MAGS_API_TOKEN" \
|
|
376
|
-
-H "Content-Type: application/json" \
|
|
377
|
-
-d '{
|
|
378
|
-
"script": "echo Hello World",
|
|
379
|
-
"type": "inline",
|
|
380
|
-
"workspace_id": "myproject",
|
|
381
|
-
"persistent": true,
|
|
382
|
-
"no_sleep": true
|
|
383
|
-
}'
|
|
177
|
+
// Stop a job
|
|
178
|
+
await mags.stop(requestId);
|
|
384
179
|
```
|
|
385
180
|
|
|
386
|
-
## Job Status Values
|
|
387
|
-
|
|
388
|
-
| Status | Description |
|
|
389
|
-
|--------|-------------|
|
|
390
|
-
| `pending` | Job queued, waiting for VM |
|
|
391
|
-
| `running` | Script executing |
|
|
392
|
-
| `sleeping` | Persistent VM idle (wakes on request) |
|
|
393
|
-
| `completed` | Script finished successfully |
|
|
394
|
-
| `error` | Script failed |
|
|
395
|
-
|
|
396
|
-
## VM Environment
|
|
397
|
-
|
|
398
|
-
Each VM runs Alpine Linux with hostname `mags-vm` and includes:
|
|
399
|
-
|
|
400
|
-
- `/root` - Persistent home directory (synced to S3)
|
|
401
|
-
- `/jfs` - Direct JuiceFS mount
|
|
402
|
-
- Common tools: curl, wget, git, python3, nodejs
|
|
403
|
-
- Package manager: `apk add <package>`
|
|
404
|
-
|
|
405
|
-
### Installing Packages
|
|
406
|
-
|
|
407
|
-
```bash
|
|
408
|
-
# Python packages
|
|
409
|
-
mags run 'apk add python3 py3-pip && pip install requests flask pandas'
|
|
410
|
-
|
|
411
|
-
# Node.js packages
|
|
412
|
-
mags run 'apk add nodejs npm && npm install -g express'
|
|
413
|
-
|
|
414
|
-
# System packages
|
|
415
|
-
mags run 'apk add ffmpeg imagemagick'
|
|
416
|
-
```
|
|
417
|
-
|
|
418
|
-
## Performance
|
|
419
|
-
|
|
420
|
-
| Metric | Value |
|
|
421
|
-
|--------|-------|
|
|
422
|
-
| Warm start | ~300ms |
|
|
423
|
-
| Cold start | ~4 seconds |
|
|
424
|
-
| Script overhead | ~50ms |
|
|
425
|
-
| Workspace sync | Every 30 seconds |
|
|
426
|
-
|
|
427
181
|
## Environment Variables
|
|
428
182
|
|
|
429
183
|
| Variable | Description | Default |
|
|
@@ -431,49 +185,12 @@ mags run 'apk add ffmpeg imagemagick'
|
|
|
431
185
|
| `MAGS_API_TOKEN` | Your API token (required) | - |
|
|
432
186
|
| `MAGS_API_URL` | API endpoint | https://api.magpiecloud.com |
|
|
433
187
|
|
|
434
|
-
##
|
|
435
|
-
|
|
436
|
-
### "API token required"
|
|
437
|
-
|
|
438
|
-
Set your API token:
|
|
439
|
-
```bash
|
|
440
|
-
mags login
|
|
441
|
-
# or
|
|
442
|
-
export MAGS_API_TOKEN="your-token-here"
|
|
443
|
-
```
|
|
444
|
-
|
|
445
|
-
### "Job timed out"
|
|
446
|
-
|
|
447
|
-
Increase the timeout or check if your script is hanging:
|
|
448
|
-
```bash
|
|
449
|
-
mags run --timeout 600 'long-running-script.sh'
|
|
450
|
-
```
|
|
451
|
-
|
|
452
|
-
### "Workspace not found"
|
|
453
|
-
|
|
454
|
-
Workspace IDs are case-sensitive. Check with:
|
|
455
|
-
```bash
|
|
456
|
-
mags list
|
|
457
|
-
```
|
|
458
|
-
|
|
459
|
-
### URL not accessible
|
|
460
|
-
|
|
461
|
-
Make sure you're using both `-p` (persistent) and `--url` flags, and your app is listening on the correct port:
|
|
462
|
-
```bash
|
|
463
|
-
mags run -p --url --port 3000 'node server.js'
|
|
464
|
-
```
|
|
465
|
-
|
|
466
|
-
### SSH connection issues
|
|
467
|
-
|
|
468
|
-
SSH connects through our proxy. If you have issues:
|
|
469
|
-
1. Ensure the job is running: `mags status <id>`
|
|
470
|
-
2. Try reconnecting: `mags ssh <workspace>`
|
|
471
|
-
|
|
472
|
-
## Support
|
|
188
|
+
## Performance
|
|
473
189
|
|
|
474
|
-
-
|
|
475
|
-
-
|
|
476
|
-
-
|
|
190
|
+
- **Warm start**: <100ms (VM from pool)
|
|
191
|
+
- **Cold start**: ~4 seconds (new VM boot)
|
|
192
|
+
- **Script overhead**: ~50ms
|
|
193
|
+
- **Workspace sync**: Every 30 seconds
|
|
477
194
|
|
|
478
195
|
## License
|
|
479
196
|
|