@magpiecloud/mags 1.5.1 → 1.6.1

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.
Files changed (42) hide show
  1. package/API.md +381 -0
  2. package/Mags-API.postman_collection.json +374 -0
  3. package/QUICKSTART.md +283 -0
  4. package/README.md +287 -79
  5. package/bin/mags.js +151 -27
  6. package/deploy-page.sh +171 -0
  7. package/index.js +1 -163
  8. package/mags +0 -0
  9. package/mags.sh +270 -0
  10. package/nodejs/README.md +191 -0
  11. package/nodejs/bin/mags.js +1146 -0
  12. package/nodejs/index.js +326 -0
  13. package/nodejs/package.json +42 -0
  14. package/package.json +4 -15
  15. package/python/INTEGRATION.md +747 -0
  16. package/python/README.md +139 -0
  17. package/python/dist/magpie_mags-1.0.0-py3-none-any.whl +0 -0
  18. package/python/dist/magpie_mags-1.0.0.tar.gz +0 -0
  19. package/python/examples/demo.py +181 -0
  20. package/python/pyproject.toml +39 -0
  21. package/python/src/magpie_mags.egg-info/PKG-INFO +164 -0
  22. package/python/src/magpie_mags.egg-info/SOURCES.txt +9 -0
  23. package/python/src/magpie_mags.egg-info/dependency_links.txt +1 -0
  24. package/python/src/magpie_mags.egg-info/requires.txt +1 -0
  25. package/python/src/magpie_mags.egg-info/top_level.txt +1 -0
  26. package/python/src/mags/__init__.py +6 -0
  27. package/python/src/mags/client.py +283 -0
  28. package/skill.md +153 -0
  29. package/website/api.html +927 -0
  30. package/website/claude-skill.html +483 -0
  31. package/website/cookbook/hn-marketing.html +410 -0
  32. package/website/cookbook/hn-marketing.sh +50 -0
  33. package/website/cookbook.html +278 -0
  34. package/website/env.js +4 -0
  35. package/website/index.html +718 -0
  36. package/website/llms.txt +242 -0
  37. package/website/login.html +88 -0
  38. package/website/mags.md +171 -0
  39. package/website/script.js +425 -0
  40. package/website/styles.css +845 -0
  41. package/website/tokens.html +171 -0
  42. package/website/usage.html +187 -0
@@ -0,0 +1,242 @@
1
+ # Mags
2
+
3
+ > Instant sandboxes and runtime environments
4
+
5
+ Mags is a CLI, SDK, and API for running scripts on isolated microVMs with persistent workspaces, file upload, cron scheduling, and optional URL access.
6
+
7
+ ## Quickstart
8
+
9
+ Install the CLI:
10
+ ```
11
+ npm install -g @magpiecloud/mags
12
+ ```
13
+
14
+ Authenticate:
15
+ ```
16
+ mags login
17
+ ```
18
+
19
+ Run your first script:
20
+ ```
21
+ mags run 'echo Hello World'
22
+ ```
23
+
24
+ ## Core CLI Commands
25
+
26
+ - `mags login` — Authenticate and save credentials
27
+ - `mags logout` — Remove saved credentials
28
+ - `mags whoami` — Check auth status
29
+ - `mags new <workspace>` — Create a persistent VM workspace
30
+ - `mags run <script>` — Execute a script on a microVM
31
+ - `mags ssh <workspace>` — Open an SSH session into a workspace
32
+ - `mags url <job-id>` — Enable public URL access for a running job
33
+ - `mags list` — List recent jobs
34
+ - `mags logs <job-id>` — View job logs
35
+ - `mags status <job-id>` — Check job status
36
+ - `mags stop <job-id>` — Stop a running job
37
+
38
+ ## Run Options
39
+
40
+ | Flag | Description |
41
+ |------|-------------|
42
+ | `-w, --workspace <id>` | Persist files with a named workspace |
43
+ | `-n, --name <name>` | Job name for easier reference |
44
+ | `-p, --persistent` | Keep VM alive after script for URL or SSH |
45
+ | `-e, --ephemeral` | No workspace, no S3 sync (fastest). Cannot combine with -w or -p |
46
+ | `-f, --file <path>` | Upload a local file into /root/ in the VM (repeatable) |
47
+ | `--url` | Enable public URL (requires -p) |
48
+ | `--port <port>` | Port to expose (default: 8080) |
49
+ | `--startup-command <cmd>` | Command to run when a VM wakes |
50
+
51
+ ## File Upload
52
+
53
+ Upload local files into the VM before your script runs. Files appear at `/root/<filename>`.
54
+
55
+ ```
56
+ # Single file
57
+ mags run -f script.py 'python3 script.py'
58
+
59
+ # Multiple files
60
+ mags run -f analyze.py -f data.csv 'python3 analyze.py'
61
+
62
+ # With workspace persistence
63
+ mags run -w my-project -f config.json -f app.js 'cp *.js *.json /root/ && cd /root && npm install'
64
+ ```
65
+
66
+ ## Cron Scheduling
67
+
68
+ Schedule recurring jobs with standard cron expressions.
69
+
70
+ ```
71
+ # Create a cron job
72
+ mags cron add --name "daily-backup" --schedule "0 0 * * *" 'tar czf /root/backup.tar.gz /root/data'
73
+
74
+ # Create with workspace
75
+ mags cron add --name "health-check" --schedule "*/5 * * * *" -w monitors 'curl -sf https://myapp.com/health'
76
+
77
+ # List cron jobs
78
+ mags cron list
79
+
80
+ # Remove a cron job
81
+ mags cron remove <id>
82
+
83
+ # Enable / disable
84
+ mags cron enable <id>
85
+ mags cron disable <id>
86
+ ```
87
+
88
+ ### Cron flags for `add`
89
+
90
+ | Flag | Description |
91
+ |------|-------------|
92
+ | `-n, --name` | Cron job name (required) |
93
+ | `-s, --schedule` | Cron expression, e.g. "0 */2 * * *" (required) |
94
+ | `-w, --workspace` | Workspace ID for persistent storage |
95
+ | `-p, --persistent` | Keep VM alive after script |
96
+
97
+ ## Workspaces
98
+
99
+ Workspaces persist files, installed packages, and configuration between runs. Running processes, in-memory state, and open ports reset between sessions.
100
+
101
+ ## Complex Project Workflow
102
+
103
+ For multi-file projects, the recommended pattern is: create files locally, upload them, then run.
104
+
105
+ ```
106
+ # Step 1: Upload files and install deps in a workspace
107
+ mags run -w my-project -f server.js -f package.json \
108
+ 'cp *.js *.json /root/ && cd /root && npm install'
109
+
110
+ # Step 2: Test run
111
+ mags run -w my-project 'cd /root && node server.js'
112
+
113
+ # Step 3: Run with public URL
114
+ mags run -w my-project -p --url --port 3000 'cd /root && node server.js'
115
+
116
+ # Step 4: Schedule recurring run with cron
117
+ mags cron add --name "my-server" --schedule "0 */6 * * *" -w my-project \
118
+ 'cd /root && node server.js'
119
+ ```
120
+
121
+ ## Ephemeral Mode
122
+
123
+ For the fastest runs with no workspace or S3 sync overhead:
124
+ ```
125
+ mags run -e 'uname -a && df -h'
126
+ ```
127
+
128
+ ## API
129
+
130
+ Base URL: `https://api.magpiecloud.com/api/v1`
131
+
132
+ ### Authentication
133
+
134
+ Use a Bearer token in the Authorization header:
135
+ ```
136
+ Authorization: Bearer <your-api-token>
137
+ ```
138
+
139
+ Generate tokens at https://mags.run/tokens or via `mags login`.
140
+
141
+ ### Job Endpoints
142
+
143
+ - `POST /mags-jobs` — Submit a job (supports `file_ids` array for uploaded files)
144
+ - `GET /mags-jobs` — List jobs
145
+ - `GET /mags-jobs/{id}/status` — Get job status
146
+ - `GET /mags-jobs/{id}/logs` — Get job logs
147
+ - `POST /mags-jobs/{id}/access` — Enable URL or SSH access
148
+ - `PATCH /mags-jobs/{id}` — Update startup command
149
+
150
+ ### File Endpoints
151
+
152
+ - `POST /mags-files` — Upload file(s) via multipart/form-data (max 100MB)
153
+
154
+ ### Cron Endpoints
155
+
156
+ - `POST /mags-cron` — Create a cron job
157
+ - `GET /mags-cron` — List cron jobs
158
+ - `GET /mags-cron/{id}` — Get a specific cron job
159
+ - `PATCH /mags-cron/{id}` — Update a cron job
160
+ - `DELETE /mags-cron/{id}` — Delete a cron job
161
+
162
+ ### Submit a Job
163
+
164
+ ```
165
+ curl -X POST https://api.magpiecloud.com/api/v1/mags-jobs \
166
+ -H "Authorization: Bearer $MAGS_API_TOKEN" \
167
+ -H "Content-Type: application/json" \
168
+ -d '{
169
+ "script": "echo Hello World",
170
+ "type": "inline",
171
+ "workspace_id": "myproject",
172
+ "persistent": true
173
+ }'
174
+ ```
175
+
176
+ ## Node.js SDK
177
+
178
+ ```
179
+ npm install @magpiecloud/mags
180
+ ```
181
+
182
+ ```js
183
+ const Mags = require('@magpiecloud/mags');
184
+
185
+ const mags = new Mags({
186
+ apiToken: process.env.MAGS_API_TOKEN
187
+ });
188
+
189
+ // Run a script
190
+ const result = await mags.runAndWait('echo Hello World');
191
+ console.log(result.logs);
192
+
193
+ // Upload files
194
+ const fileIds = await mags.uploadFiles(['script.py', 'data.csv']);
195
+ const result = await mags.run('python3 script.py', { fileIds });
196
+
197
+ // Cron jobs
198
+ await mags.cronCreate({
199
+ name: 'daily-backup',
200
+ cronExpression: '0 0 * * *',
201
+ script: 'tar czf backup.tar.gz /data',
202
+ workspaceId: 'my-workspace'
203
+ });
204
+ const { cron_jobs } = await mags.cronList();
205
+ await mags.cronDelete(id);
206
+ ```
207
+
208
+ ## Claude Code Integration
209
+
210
+ Install the Mags skill for Claude Code:
211
+ ```
212
+ mags setup-claude
213
+ ```
214
+
215
+ Then use `/mags <description>` in Claude Code to run scripts in microVMs.
216
+
217
+ ## VM Environment
218
+
219
+ - Alpine Linux base image
220
+ - Hostname: `mags-vm`
221
+ - Persistent home: `/root` (synced to S3 with workspaces)
222
+ - JuiceFS mount: `/jfs`
223
+ - Package manager: `apk`
224
+ - Pre-installed: curl, wget, git, python3, node, vim, nano
225
+
226
+ ## Cookbook
227
+
228
+ Ready-to-run recipes at https://mags.run/cookbook including:
229
+ - Quick script runs
230
+ - Persistent Python/Node workspaces
231
+ - Exposing web servers with URLs
232
+ - HN Marketing Digest cron job
233
+
234
+ ## Links
235
+
236
+ - Website: https://mags.run
237
+ - Dashboard: https://mags.run/dashboard
238
+ - API Tokens: https://mags.run/tokens
239
+ - API Reference: https://mags.run/api
240
+ - Cookbook: https://mags.run/cookbook
241
+ - Claude Skill: https://mags.run/claude-skill
242
+ - Documentation: https://mags.run/#cli
@@ -0,0 +1,88 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
6
+ <title>Mags Login</title>
7
+ <meta name="description" content="Sign in to Mags with Google or email." />
8
+ <meta name="api-base" content="https://api.magpiecloud.com" />
9
+ <meta name="auth-base" content="https://api.magpiecloud.com" />
10
+ <link rel="stylesheet" href="styles.css?v=2" />
11
+ <script src="env.js"></script>
12
+ </head>
13
+ <body>
14
+ <div class="backdrop"></div>
15
+
16
+ <header class="site-header">
17
+ <div class="container nav">
18
+ <div class="brand">
19
+ <span class="logo">Mags</span>
20
+ <span class="tag">Sign in</span>
21
+ </div>
22
+ <nav class="nav-links">
23
+ <a href="index.html">Home</a>
24
+ <a href="index.html#quickstart">Quickstart</a>
25
+ <a href="index.html#cli">CLI</a>
26
+ <a href="index.html#api">API</a>
27
+ </nav>
28
+ <div class="nav-cta">
29
+ <a class="button ghost" href="index.html">Back to home</a>
30
+ </div>
31
+ </div>
32
+ </header>
33
+
34
+ <main class="auth-page">
35
+ <div class="container auth-layout">
36
+ <div class="auth-shell">
37
+ <div>
38
+ <span class="pill">Login</span>
39
+ <h1 class="auth-title">Sign in to Mags.</h1>
40
+ <p class="auth-subtitle">Use Google or your email and password.</p>
41
+ </div>
42
+
43
+ <button class="button full" type="button" data-google-login>Continue with Google</button>
44
+
45
+ <div class="auth-divider"><span>or</span></div>
46
+
47
+ <form class="login-form" data-login-form>
48
+ <div class="form-group">
49
+ <label class="form-label" for="login-email">Email</label>
50
+ <input class="input" type="email" id="login-email" name="email" required />
51
+ </div>
52
+ <div class="form-group">
53
+ <label class="form-label" for="login-password">Password</label>
54
+ <input class="input" type="password" id="login-password" name="password" required />
55
+ </div>
56
+ <button class="button full" type="submit">Sign in</button>
57
+ <p class="form-message" data-login-message></p>
58
+ </form>
59
+
60
+ <div class="form-links">
61
+ <a data-auth-link="/auth/forgot-password" href="#">Forgot password?</a>
62
+ <a data-auth-link="/auth/register" href="#">Create an account</a>
63
+ </div>
64
+ </div>
65
+ </div>
66
+ </main>
67
+
68
+ <footer class="site-footer">
69
+ <div class="container footer-grid">
70
+ <div>
71
+ <div class="brand">
72
+ <span class="logo">Mags</span>
73
+ <span class="tag">Instant sandboxes and runtime environments</span>
74
+ </div>
75
+ <p>Build, test, and run from clean microVMs whenever you need them.</p>
76
+ </div>
77
+ <div class="footer-links">
78
+ <a href="index.html">Home</a>
79
+ <a href="usage.html">Usage</a>
80
+ <a href="tokens.html">Tokens</a>
81
+ <a href="claude-skill.html">Claude Skill</a>
82
+ </div>
83
+ </div>
84
+ </footer>
85
+
86
+ <script src="script.js"></script>
87
+ </body>
88
+ </html>
@@ -0,0 +1,171 @@
1
+ # Mags Job Runner
2
+
3
+ Execute scripts on Magpie's instant microVM infrastructure using the `mags` CLI.
4
+
5
+ ## How to Use
6
+
7
+ IMPORTANT: Always use the `mags` CLI tool. NEVER use curl or direct API calls.
8
+ The CLI handles authentication, polling, and output automatically.
9
+
10
+ When the user says `/mags <command or description>`, run it using the `mags` CLI.
11
+
12
+ ## Commands
13
+
14
+ ### Run a script
15
+ ```bash
16
+ mags run '<script>'
17
+ ```
18
+
19
+ ### Run with a persistent workspace (changes saved to S3)
20
+ ```bash
21
+ mags run -w <workspace-name> '<script>'
22
+ ```
23
+
24
+ ### Run a persistent VM with public URL
25
+ ```bash
26
+ mags run -p --url '<script>'
27
+ ```
28
+
29
+ ### Run with workspace + persistence + URL + custom port
30
+ ```bash
31
+ mags run -w <workspace> -p --url --port 3000 '<script>'
32
+ ```
33
+
34
+ ### Create a new persistent VM (stays alive for SSH)
35
+ ```bash
36
+ mags new <name>
37
+ ```
38
+
39
+ ### SSH into a running VM
40
+ ```bash
41
+ mags ssh <name-or-id>
42
+ ```
43
+
44
+ ### Check job status
45
+ ```bash
46
+ mags status <name-or-id>
47
+ ```
48
+
49
+ ### View job logs
50
+ ```bash
51
+ mags logs <name-or-id>
52
+ ```
53
+
54
+ ### List recent jobs
55
+ ```bash
56
+ mags list
57
+ ```
58
+
59
+ ### Enable URL access on existing job
60
+ ```bash
61
+ mags url <name-or-id> [port]
62
+ ```
63
+
64
+ ### Stop a running job
65
+ ```bash
66
+ mags stop <name-or-id>
67
+ ```
68
+
69
+ ### Run without workspace (ephemeral, fastest)
70
+ ```bash
71
+ mags run -e '<script>'
72
+ ```
73
+
74
+ ### Upload files into the VM before running
75
+ ```bash
76
+ mags run -f script.py -f data.csv 'python3 script.py'
77
+ ```
78
+
79
+ ### Cron: schedule recurring jobs
80
+ ```bash
81
+ mags cron add --name "daily-backup" --schedule "0 0 * * *" 'tar czf /root/backup.tar.gz /root/data'
82
+ mags cron list
83
+ mags cron remove <id>
84
+ mags cron enable <id>
85
+ mags cron disable <id>
86
+ ```
87
+
88
+ ## CLI Flags for `run`
89
+
90
+ | Flag | Description |
91
+ |------|-------------|
92
+ | `-w, --workspace <id>` | Persistent workspace (S3 sync) |
93
+ | `-n, --name <name>` | Job name for easier reference |
94
+ | `-p, --persistent` | Keep VM alive after script |
95
+ | `-e, --ephemeral` | No workspace, no S3 sync (fastest). Cannot combine with -w or -p |
96
+ | `-f, --file <path>` | Upload a file into /root/ in the VM (repeatable) |
97
+ | `--url` | Enable public URL (requires -p) |
98
+ | `--port <port>` | Port to expose (default: 8080) |
99
+ | `--startup-command <cmd>` | Command to run when VM wakes |
100
+
101
+ ## Workflow
102
+
103
+ When the user asks to run something on mags:
104
+
105
+ 1. **Parse the request** - determine the script/command and any flags needed
106
+ 2. **Run via CLI** - use `mags run '<script>'` (with appropriate flags)
107
+ 3. **Show the output** - the CLI handles polling and displays results automatically
108
+
109
+ ## Examples
110
+
111
+ ### Simple command
112
+ User: `/mags echo Hello World`
113
+ ```bash
114
+ mags run 'echo Hello World'
115
+ ```
116
+
117
+ ### Install packages and run code
118
+ User: `/mags run python with numpy`
119
+ ```bash
120
+ mags run 'apk add python3 py3-pip && pip install numpy && python3 -c "import numpy; print(numpy.array([1,2,3]))"'
121
+ ```
122
+
123
+ ### Deploy a web server
124
+ User: `/mags deploy a python web server`
125
+ ```bash
126
+ mags run -p --url 'python3 -m http.server 8080'
127
+ ```
128
+
129
+ ### Persistent workspace
130
+ User: `/mags set up a node project in my-app workspace`
131
+ ```bash
132
+ mags run -w my-app 'apk add nodejs npm && mkdir -p /workspace/my-app && cd /workspace/my-app && npm init -y'
133
+ ```
134
+
135
+ ### Ephemeral (no workspace, fastest)
136
+ User: `/mags quickly check disk info`
137
+ ```bash
138
+ mags run -e 'df -h && uname -a'
139
+ ```
140
+
141
+ ### Upload a file and run it
142
+ User: `/mags run my local script.py in a VM`
143
+ ```bash
144
+ mags run -f script.py 'python3 script.py'
145
+ ```
146
+
147
+ ### Upload multiple files
148
+ User: `/mags run my analysis with the data file`
149
+ ```bash
150
+ mags run -f analyze.py -f data.csv 'python3 analyze.py'
151
+ ```
152
+
153
+ ### Schedule a cron job
154
+ User: `/mags schedule a health check every hour`
155
+ ```bash
156
+ mags cron add --name "health-check" --schedule "0 * * * *" 'curl -sf https://example.com/health || echo FAIL'
157
+ ```
158
+
159
+ ## Authentication
160
+
161
+ The CLI reads credentials from `~/.mags/config.json` (set via `mags login`).
162
+ If not authenticated, tell the user to run `mags login` first.
163
+ Do NOT hardcode tokens or use environment variables for auth.
164
+
165
+ ## Important Rules
166
+
167
+ 1. ALWAYS use `mags run '...'` - never use curl or direct API calls
168
+ 2. ALWAYS quote the script argument in single quotes
169
+ 3. The CLI handles job submission, polling, and log retrieval automatically
170
+ 4. For multi-line scripts, use semicolons or `&&` to chain commands
171
+ 5. If the user wants to create a VM and SSH in, use `mags new <name>` then `mags ssh <name>`