@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.
Files changed (43) hide show
  1. package/README.md +95 -378
  2. package/bin/mags.js +196 -104
  3. package/index.js +6 -52
  4. package/package.json +22 -4
  5. package/API.md +0 -388
  6. package/Mags-API.postman_collection.json +0 -374
  7. package/QUICKSTART.md +0 -295
  8. package/deploy-page.sh +0 -171
  9. package/mags +0 -0
  10. package/mags.sh +0 -270
  11. package/nodejs/README.md +0 -197
  12. package/nodejs/bin/mags.js +0 -1146
  13. package/nodejs/index.js +0 -642
  14. package/nodejs/package.json +0 -42
  15. package/python/INTEGRATION.md +0 -800
  16. package/python/README.md +0 -161
  17. package/python/dist/magpie_mags-1.3.5-py3-none-any.whl +0 -0
  18. package/python/dist/magpie_mags-1.3.5.tar.gz +0 -0
  19. package/python/examples/demo.py +0 -181
  20. package/python/pyproject.toml +0 -39
  21. package/python/src/magpie_mags.egg-info/PKG-INFO +0 -182
  22. package/python/src/magpie_mags.egg-info/SOURCES.txt +0 -9
  23. package/python/src/magpie_mags.egg-info/dependency_links.txt +0 -1
  24. package/python/src/magpie_mags.egg-info/requires.txt +0 -1
  25. package/python/src/magpie_mags.egg-info/top_level.txt +0 -1
  26. package/python/src/mags/__init__.py +0 -6
  27. package/python/src/mags/client.py +0 -573
  28. package/python/test_sdk.py +0 -78
  29. package/skill.md +0 -153
  30. package/website/api.html +0 -1095
  31. package/website/claude-skill.html +0 -481
  32. package/website/cookbook/hn-marketing.html +0 -410
  33. package/website/cookbook/hn-marketing.sh +0 -42
  34. package/website/cookbook.html +0 -282
  35. package/website/env.js +0 -4
  36. package/website/index.html +0 -801
  37. package/website/llms.txt +0 -334
  38. package/website/login.html +0 -108
  39. package/website/mags.md +0 -210
  40. package/website/script.js +0 -453
  41. package/website/styles.css +0 -908
  42. package/website/tokens.html +0 -169
  43. package/website/usage.html +0 -185
package/website/llms.txt DELETED
@@ -1,334 +0,0 @@
1
- # Mags
2
-
3
- > Secure cloud sandboxes for AI agents and developers
4
-
5
- Mags is a CLI, SDK, and API for running scripts on isolated microVMs with 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 <name> [-p]` — Create a VM sandbox (add -p for S3 data persistence)
30
- - `mags run <script>` — Execute a script on a microVM
31
- - `mags ssh <name>` — Open an SSH session into a sandbox (auto-starts if needed)
32
- - `mags exec <name> <command>` — Run a command on an existing sandbox
33
- - `mags list` — List recent jobs
34
- - `mags logs <name|id>` — View job logs
35
- - `mags status <name|id>` — Check job status
36
- - `mags stop <name|id>` — Stop a running job
37
- - `mags sync <name|id>` — Sync workspace to S3 without stopping the VM
38
- - `mags resize <name> --disk <GB>` — Resize disk for a workspace
39
- - `mags url <name|id> [port]` — Enable public URL access for a running job
40
- - `mags url alias <subdomain> <name>` — Create a stable URL alias
41
- - `mags url alias list` — List URL aliases
42
- - `mags url alias remove <subdomain>` — Remove a URL alias
43
- - `mags set <name|id> --no-sleep` — Never auto-sleep this VM
44
- - `mags set <name|id> --sleep` — Re-enable auto-sleep
45
- - `mags workspace list` — List persistent workspaces
46
- - `mags workspace delete <id>` — Delete workspace and cloud data
47
- - `mags browser [name]` — Start a Chromium browser session (CDP access)
48
-
49
- ## Run Options
50
-
51
- `-w` and `-n` are aliases — both set the job name and workspace ID to the same value.
52
-
53
- | Flag | Description |
54
- |------|-------------|
55
- | `-w, --workspace <name>` | Name the job and workspace. Data stays local to the VM only (not synced to S3). Useful for data analysis where you don't need artifacts to persist. Combine with `-p` to sync to S3 and persist. |
56
- | `-n, --name <name>` | Alias for `-w` |
57
- | `-p, --persistent` | Keep VM alive after script and sync workspace to S3. Files persist across runs indefinitely. Required for URL, SSH, and cloud persistence. |
58
- | `--base <workspace>` | Mount an existing workspace read-only as a starting point (OverlayFS). Use with `-w` to fork into a new workspace. |
59
- | `--no-sleep` | Never auto-sleep this VM (requires -p) |
60
- | `-e, --ephemeral` | No workspace, no sync (fastest). Cannot combine with -w, -p, or --base |
61
- | `-f, --file <path>` | Upload a local file into /root/ in the VM (repeatable) |
62
- | `--url` | Enable public URL (requires -p) |
63
- | `--port <port>` | Port to expose (default: 8080) |
64
- | `--disk <GB>` | Custom disk size in GB (default: 2) |
65
- | `--startup-command <cmd>` | Command to run when a VM wakes from sleep |
66
-
67
- ## Workspace Modes
68
-
69
- | Flags | Behavior |
70
- |-------|----------|
71
- | (none) | Ephemeral. No workspace, no persistence. |
72
- | `-w myproject` | Local workspace. Data stays on the VM only (~5 min warm cache after job completes). Not synced to S3. Good for data analysis and throwaway work. |
73
- | `-w myproject -p` | Persistent workspace. VM stays alive, data synced to S3. Files survive across runs indefinitely. |
74
- | `--base golden` | Read-only base image. Changes discarded after run. |
75
- | `--base golden -w fork-1` | Fork: starts from golden, saves changes to fork-1 (local only without -p). |
76
- | `--base golden -w fork-1 -p` | Fork with persistence: starts from golden, saves to fork-1 in S3. |
77
- | `-e` | Explicit ephemeral. Same as no flags but cannot accidentally combine with -w or -p. |
78
-
79
- ## File Upload
80
-
81
- Upload local files into the VM before your script runs. Files appear at `/root/<filename>`.
82
-
83
- ```
84
- # Single file
85
- mags run -f script.py 'python3 script.py'
86
-
87
- # Multiple files
88
- mags run -f analyze.py -f data.csv 'python3 analyze.py'
89
-
90
- # With persistent workspace
91
- mags run -w my-project -p -f config.json -f app.js 'cp *.js *.json /root/ && cd /root && npm install'
92
- ```
93
-
94
- ## Cron Scheduling
95
-
96
- Schedule recurring jobs with standard cron expressions.
97
-
98
- ```
99
- # Create a cron job
100
- mags cron add --name "daily-backup" --schedule "0 0 * * *" 'tar czf /root/backup.tar.gz /root/data'
101
-
102
- # Create with workspace
103
- mags cron add --name "health-check" --schedule "*/5 * * * *" -w monitors 'curl -sf https://myapp.com/health'
104
-
105
- # List cron jobs
106
- mags cron list
107
-
108
- # Remove a cron job
109
- mags cron remove <id>
110
-
111
- # Enable / disable
112
- mags cron enable <id>
113
- mags cron disable <id>
114
- ```
115
-
116
- ### Cron flags for `add`
117
-
118
- | Flag | Description |
119
- |------|-------------|
120
- | `-n, --name` | Cron job name (required) |
121
- | `-s, --schedule` | Cron expression, e.g. "0 */2 * * *" (required) |
122
- | `-w, --workspace` | Workspace ID for storage |
123
- | `-p, --persistent` | Keep VM alive after script |
124
-
125
- ## Complex Project Workflow
126
-
127
- For multi-file projects, the recommended pattern is: create files locally, upload them, then run persistently.
128
-
129
- ```
130
- # Step 1: Upload files and install deps in a persistent workspace
131
- mags run -w my-project -p -f server.js -f package.json \
132
- 'cp *.js *.json /root/ && cd /root && npm install'
133
-
134
- # Step 2: Test run (reuses the persistent workspace)
135
- mags run -w my-project -p 'cd /root && node server.js'
136
-
137
- # Step 3: Run with public URL
138
- mags run -w my-project -p --url --port 3000 'cd /root && node server.js'
139
-
140
- # Step 4: Schedule recurring run with cron
141
- mags cron add --name "my-server" --schedule "0 */6 * * *" -w my-project \
142
- 'cd /root && node server.js'
143
- ```
144
-
145
- ## Data Analysis Workflow
146
-
147
- For throwaway analysis where you need a workspace but don't care about persisting artifacts:
148
-
149
- ```
150
- # Upload data and analyze — workspace is local only, no S3 overhead
151
- mags run -w analysis -f data.csv 'python3 -c "
152
- import csv
153
- with open(\"/root/data.csv\") as f:
154
- reader = csv.reader(f)
155
- for row in reader:
156
- print(row)
157
- "'
158
-
159
- # Results printed to stdout (use `mags logs` to retrieve)
160
- # VM and data cleaned up automatically after ~5 minutes
161
- ```
162
-
163
- ## Ephemeral Mode
164
-
165
- For the fastest runs with no workspace at all:
166
- ```
167
- mags run -e 'uname -a && df -h'
168
- ```
169
-
170
- ## API
171
-
172
- Base URL: `https://api.magpiecloud.com/api/v1`
173
-
174
- ### Authentication
175
-
176
- Use a Bearer token in the Authorization header:
177
- ```
178
- Authorization: Bearer <your-api-token>
179
- ```
180
-
181
- Generate tokens at https://mags.run/tokens or via `mags login`.
182
-
183
- ### Job Endpoints
184
-
185
- - `POST /mags-jobs` — Submit a job (supports `file_ids` array for uploaded files)
186
- - `GET /mags-jobs` — List jobs
187
- - `GET /mags-jobs/{id}/status` — Get job status
188
- - `GET /mags-jobs/{id}/logs` — Get job logs
189
- - `POST /mags-jobs/{id}/access` — Enable URL or SSH access
190
- - `PATCH /mags-jobs/{id}` — Update job settings (startup_command, no_sleep)
191
-
192
- ### File Endpoints
193
-
194
- - `POST /mags-files` — Upload file(s) via multipart/form-data (max 100MB)
195
-
196
- ### Workspace Endpoints
197
-
198
- - `GET /mags-workspaces` — List workspaces
199
- - `DELETE /mags-workspaces/{id}` — Delete workspace and S3 data
200
-
201
- ### Cron Endpoints
202
-
203
- - `POST /mags-cron` — Create a cron job
204
- - `GET /mags-cron` — List cron jobs
205
- - `GET /mags-cron/{id}` — Get a specific cron job
206
- - `PATCH /mags-cron/{id}` — Update a cron job
207
- - `DELETE /mags-cron/{id}` — Delete a cron job
208
-
209
- ### Submit a Job
210
-
211
- ```
212
- curl -X POST https://api.magpiecloud.com/api/v1/mags-jobs \
213
- -H "Authorization: Bearer $MAGS_API_TOKEN" \
214
- -H "Content-Type: application/json" \
215
- -d '{
216
- "script": "echo Hello World",
217
- "type": "inline",
218
- "workspace_id": "myproject",
219
- "persistent": true
220
- }'
221
- ```
222
-
223
- ## Python SDK
224
-
225
- ```
226
- pip install magpie-mags
227
- ```
228
-
229
- ```python
230
- from mags import Mags
231
-
232
- mags = Mags() # uses MAGS_API_TOKEN env var
233
-
234
- # Run a script and wait for result
235
- result = mags.run_and_wait('echo Hello World')
236
- print(result['logs'])
237
-
238
- # Create a sandbox (local disk)
239
- mags.new('my-project')
240
-
241
- # Create with S3 persistence
242
- mags.new('my-project', persistent=True)
243
-
244
- # Execute a command on an existing sandbox
245
- result = mags.exec('my-project', 'ls -la /root')
246
- print(result['output'])
247
-
248
- # Stop a running job
249
- mags.stop('my-project')
250
-
251
- # Enable public URL
252
- info = mags.url('my-project', port=3000)
253
- print(info['url'])
254
-
255
- # Find a job by name or workspace
256
- job = mags.find_job('my-project')
257
-
258
- # Upload files and run
259
- file_ids = mags.upload_files(['script.py', 'data.csv'])
260
- mags.run('python3 script.py', file_ids=file_ids)
261
-
262
- # Cron jobs
263
- mags.cron_create(name='daily-backup', cron_expression='0 0 * * *',
264
- script='tar czf backup.tar.gz /data', workspace_id='my-ws')
265
- mags.cron_delete(cron_id)
266
- ```
267
-
268
- ## Node.js SDK
269
-
270
- ```
271
- npm install @magpiecloud/mags
272
- ```
273
-
274
- ```js
275
- const Mags = require('@magpiecloud/mags');
276
-
277
- const mags = new Mags({
278
- apiToken: process.env.MAGS_API_TOKEN
279
- });
280
-
281
- // Run a script
282
- const result = await mags.runAndWait('echo Hello World');
283
- console.log(result.logs);
284
-
285
- // Upload files
286
- const fileIds = await mags.uploadFiles(['script.py', 'data.csv']);
287
- const result = await mags.run('python3 script.py', { fileIds });
288
-
289
- // Cron jobs
290
- await mags.cronCreate({
291
- name: 'daily-backup',
292
- cronExpression: '0 0 * * *',
293
- script: 'tar czf backup.tar.gz /data',
294
- workspaceId: 'my-workspace'
295
- });
296
- const { cron_jobs } = await mags.cronList();
297
- await mags.cronDelete(id);
298
- ```
299
-
300
- ## Claude Code Integration
301
-
302
- Install the Mags skill for Claude Code:
303
- ```
304
- mags setup-claude
305
- ```
306
-
307
- Then use `/mags <description>` in Claude Code to run scripts in microVMs.
308
-
309
- ## VM Environment
310
-
311
- - Alpine Linux base image
312
- - Hostname: `mags-vm`
313
- - Home directory: `/root`
314
- - JuiceFS mount: `/jfs` (persistent workspaces only)
315
- - Package manager: `apk`
316
- - Pre-installed: curl, wget, git, python3, node, vim, nano
317
-
318
- ## Cookbook
319
-
320
- Ready-to-run recipes at https://mags.run/cookbook including:
321
- - Quick script runs
322
- - Persistent Python/Node workspaces
323
- - Exposing web servers with URLs
324
- - HN Marketing Digest cron job
325
-
326
- ## Links
327
-
328
- - Website: https://mags.run
329
- - Dashboard: https://mags.run/dashboard
330
- - API Tokens: https://mags.run/tokens
331
- - API Reference: https://mags.run/api
332
- - Cookbook: https://mags.run/cookbook
333
- - Claude Skill: https://mags.run/claude-skill
334
- - Documentation: https://mags.run/#cli
@@ -1,108 +0,0 @@
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." />
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=6" />
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">Docs</a>
25
- <a href="api.html">API</a>
26
- <a href="cookbook.html">Cookbook</a>
27
- <a href="https://discord.gg/3avpC2nS" target="_blank" rel="noreferrer">Discord</a>
28
- </nav>
29
- <div class="nav-cta">
30
- <a class="button ghost" href="index.html">Back to home</a>
31
- </div>
32
- </div>
33
- </header>
34
-
35
- <main class="auth-page">
36
- <div class="container auth-layout">
37
- <div class="auth-shell">
38
- <div>
39
- <span class="pill">Login</span>
40
- <h1 class="auth-title">Sign in to Mags.</h1>
41
- <p class="auth-subtitle">Sign in with your Google account to get started.</p>
42
- </div>
43
-
44
- <button class="button full" type="button" data-google-login>Continue with Google</button>
45
- </div>
46
- </div>
47
- </main>
48
-
49
- <footer class="site-footer">
50
- <div class="container footer-grid">
51
- <div>
52
- <div class="brand">
53
- <span class="logo">Mags</span>
54
- <span class="tag">Instant sandboxes and runtime environments</span>
55
- </div>
56
- <p>Build, test, and run from clean microVMs whenever you need them.</p>
57
- </div>
58
- <div class="footer-links">
59
- <a href="index.html">Home</a>
60
- <a href="api.html">API</a>
61
- <a href="cookbook.html">Cookbook</a>
62
- <a href="https://discord.gg/3avpC2nS" target="_blank" rel="noreferrer">Discord</a>
63
- </div>
64
- </div>
65
- </footer>
66
-
67
- <script src="script.js?v=7"></script>
68
- <script>
69
- (function() {
70
- // Handle logout: clear tokens when ?logout=1 is present
71
- var params = new URLSearchParams(window.location.search);
72
- if (params.get('logout') === '1') {
73
- localStorage.removeItem('microvm-access-token');
74
- localStorage.removeItem('microvm-refresh-token');
75
- // Clean up the URL
76
- window.history.replaceState({}, '', 'login.html');
77
- return;
78
- }
79
-
80
- // If already logged in, redirect to next or show dashboard link
81
- var token = localStorage.getItem('microvm-access-token');
82
- if (token) {
83
- var next = params.get('next');
84
- if (next && next.startsWith('/')) {
85
- window.location.replace(next);
86
- return;
87
- }
88
- var shell = document.querySelector('.auth-shell');
89
- if (shell) {
90
- shell.innerHTML =
91
- '<div>' +
92
- '<span class="pill">Logged in</span>' +
93
- '<h1 class="auth-title">You\'re signed in.</h1>' +
94
- '<p class="auth-subtitle">You\'re already logged in to Mags.</p>' +
95
- '</div>' +
96
- '<a class="button full" href="usage.html">Go to Dashboard</a>' +
97
- '<button class="button ghost full" type="button" id="logout-btn" style="margin-top:0.75rem">Sign out</button>';
98
- document.getElementById('logout-btn').addEventListener('click', function() {
99
- localStorage.removeItem('microvm-access-token');
100
- localStorage.removeItem('microvm-refresh-token');
101
- window.location.reload();
102
- });
103
- }
104
- }
105
- })();
106
- </script>
107
- </body>
108
- </html>
package/website/mags.md DELETED
@@ -1,210 +0,0 @@
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 VM sandbox (stays alive for SSH)
35
- ```bash
36
- mags new <name> # Local disk only
37
- mags new <name> -p # With S3 data persistence
38
- ```
39
-
40
- ### Execute a command on an existing sandbox
41
- ```bash
42
- mags exec <name-or-id> '<command>'
43
- ```
44
-
45
- ### SSH into a running VM
46
- ```bash
47
- mags ssh <name-or-id>
48
- ```
49
-
50
- ### Check job status
51
- ```bash
52
- mags status <name-or-id>
53
- ```
54
-
55
- ### View job logs
56
- ```bash
57
- mags logs <name-or-id>
58
- ```
59
-
60
- ### List recent jobs
61
- ```bash
62
- mags list
63
- ```
64
-
65
- ### Enable URL access on existing job
66
- ```bash
67
- mags url <name-or-id> [port]
68
- ```
69
-
70
- ### Stop a running job
71
- ```bash
72
- mags stop <name-or-id>
73
- ```
74
-
75
- ### Update VM settings
76
- ```bash
77
- mags set <name-or-id> --no-sleep # Never auto-sleep
78
- mags set <name-or-id> --sleep # Re-enable auto-sleep
79
- ```
80
-
81
- ### Run without workspace (ephemeral, fastest)
82
- ```bash
83
- mags run -e '<script>'
84
- ```
85
-
86
- ### Upload files into the VM before running
87
- ```bash
88
- mags run -f script.py -f data.csv 'python3 script.py'
89
- ```
90
-
91
- ### Cron: schedule recurring jobs
92
- ```bash
93
- mags cron add --name "daily-backup" --schedule "0 0 * * *" 'tar czf /root/backup.tar.gz /root/data'
94
- mags cron list
95
- mags cron remove <id>
96
- mags cron enable <id>
97
- mags cron disable <id>
98
- ```
99
-
100
- ## CLI Flags for `run`
101
-
102
- | Flag | Description |
103
- |------|-------------|
104
- | `-w, --workspace <id>` | Persistent workspace (S3 sync) |
105
- | `-n, --name <name>` | Job name for easier reference |
106
- | `-p, --persistent` | Keep VM alive after script |
107
- | `--no-sleep` | Never auto-sleep this VM (requires -p) |
108
- | `-e, --ephemeral` | No workspace, no S3 sync (fastest). Cannot combine with -w or -p |
109
- | `-f, --file <path>` | Upload a file into /root/ in the VM (repeatable) |
110
- | `--url` | Enable public URL (requires -p) |
111
- | `--port <port>` | Port to expose (default: 8080) |
112
- | `--disk <GB>` | Custom disk size in GB (default: 2) |
113
- | `--startup-command <cmd>` | Command to run when VM wakes |
114
-
115
- ## Workflow
116
-
117
- When the user asks to run something on mags:
118
-
119
- 1. **Parse the request** - determine the script/command and any flags needed
120
- 2. **Run via CLI** - use `mags run '<script>'` (with appropriate flags)
121
- 3. **Show the output** - the CLI handles polling and displays results automatically
122
-
123
- ## Examples
124
-
125
- ### Simple command
126
- User: `/mags echo Hello World`
127
- ```bash
128
- mags run 'echo Hello World'
129
- ```
130
-
131
- ### Install packages and run code
132
- User: `/mags run python with numpy`
133
- ```bash
134
- mags run 'apk add python3 py3-pip && pip install numpy && python3 -c "import numpy; print(numpy.array([1,2,3]))"'
135
- ```
136
-
137
- ### Deploy a web server
138
- User: `/mags deploy a python web server`
139
- ```bash
140
- mags run -p --url 'python3 -m http.server 8080'
141
- ```
142
-
143
- ### Persistent workspace
144
- User: `/mags set up a node project in my-app workspace`
145
- ```bash
146
- mags run -w my-app 'cd /root && npm init -y && npm install express'
147
- ```
148
-
149
- ### Run more commands on existing workspace
150
- User: `/mags run my server in the my-app workspace`
151
- ```bash
152
- mags run -w my-app -p --url --port 3000 'cd /root && node index.js'
153
- ```
154
-
155
- ### Exec into existing workspace sandbox
156
- User: `/mags install lodash in my-app`
157
- ```bash
158
- mags exec my-app 'cd /root && npm install lodash'
159
- ```
160
-
161
- ### Ephemeral (no workspace, fastest)
162
- User: `/mags quickly check disk info`
163
- ```bash
164
- mags run -e 'df -h && uname -a'
165
- ```
166
-
167
- ### Upload a file and run it
168
- User: `/mags run my local script.py in a VM`
169
- ```bash
170
- mags run -f script.py 'python3 script.py'
171
- ```
172
-
173
- ### Upload multiple files
174
- User: `/mags run my analysis with the data file`
175
- ```bash
176
- mags run -f analyze.py -f data.csv 'python3 analyze.py'
177
- ```
178
-
179
- ### Run a command on an existing sandbox
180
- User: `/mags check what's running on my-app`
181
- ```bash
182
- mags exec my-app 'ps aux'
183
- ```
184
-
185
- ### Keep a VM always running (never auto-sleep)
186
- User: `/mags start a persistent server that never sleeps`
187
- ```bash
188
- mags run -w my-server -p --no-sleep --url --port 3000 'cd /root && node server.js'
189
- ```
190
-
191
- ### Schedule a cron job
192
- User: `/mags schedule a health check every hour`
193
- ```bash
194
- mags cron add --name "health-check" --schedule "0 * * * *" 'curl -sf https://example.com/health || echo FAIL'
195
- ```
196
-
197
- ## Authentication
198
-
199
- The CLI reads credentials from `~/.mags/config.json` (set via `mags login`).
200
- If not authenticated, tell the user to run `mags login` first.
201
- Do NOT hardcode tokens or use environment variables for auth.
202
-
203
- ## Important Rules
204
-
205
- 1. ALWAYS use `mags run '...'` - never use curl or direct API calls
206
- 2. ALWAYS quote the script argument in single quotes
207
- 3. The CLI handles job submission, polling, and log retrieval automatically
208
- 4. For multi-line scripts, use semicolons or `&&` to chain commands
209
- 5. If the user wants to create a VM and SSH in, use `mags new <name>` then `mags ssh <name>`
210
- 6. To run a command on an already-running sandbox, use `mags exec <name> '<command>'` instead of starting a new run