@openmuster/muster 0.0.0-stage → 0.3.1-alpha.3

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 (79) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +309 -2
  3. package/dist/args-DX9QSK1f.js +7043 -0
  4. package/dist/cli.d.ts +1 -0
  5. package/dist/cli.js +31 -0
  6. package/dist/index.d.ts +2138 -0
  7. package/dist/index.js +1951 -0
  8. package/dist/inspect/app.js +163 -0
  9. package/dist/main-CdVlnWHy.js +6 -0
  10. package/dist/main-DgrIMbeA.js +3941 -0
  11. package/dist/mcp-NueWYyQs.js +6 -0
  12. package/dist/module-C-HJjWWo.js +4 -0
  13. package/dist/module-CxoN1MOe.js +439 -0
  14. package/dist/skills/board/SKILL.md +214 -0
  15. package/dist/skills/board/references/build-a-ui.md +63 -0
  16. package/dist/skills/board/references/claude.md +54 -0
  17. package/dist/skills/board/references/codex.md +61 -0
  18. package/dist/skills/board/references/software-factory.md +89 -0
  19. package/dist/skills/board/references/swarm.md +165 -0
  20. package/dist/skills/configure-factory/SKILL.md +116 -0
  21. package/dist/skills/loop-card/SKILL.md +95 -0
  22. package/dist/steps-DtzUdcBE.js +3175 -0
  23. package/docs/01-concepts/01-overview.md +78 -0
  24. package/docs/01-concepts/02-boards.md +71 -0
  25. package/docs/01-concepts/03-channels.md +56 -0
  26. package/docs/01-concepts/04-threads.md +73 -0
  27. package/docs/01-concepts/05-labels.md +65 -0
  28. package/docs/01-concepts/06-actors.md +66 -0
  29. package/docs/01-concepts/07-events.md +133 -0
  30. package/docs/01-concepts/08-tasks.md +248 -0
  31. package/docs/01-concepts/09-watchers.md +175 -0
  32. package/docs/01-concepts/10-schedules.md +39 -0
  33. package/docs/01-concepts/11-access.md +185 -0
  34. package/docs/01-concepts/12-files-and-data.md +79 -0
  35. package/docs/01-concepts/13-budgets.md +35 -0
  36. package/docs/01-concepts/14-runners.md +103 -0
  37. package/docs/01-concepts/15-outgoing-webhooks.md +177 -0
  38. package/docs/01-concepts/16-workflows.md +350 -0
  39. package/docs/01-concepts/17-board-module.md +124 -0
  40. package/docs/01-quickstart.md +140 -0
  41. package/docs/02-sync/01-overview.md +246 -0
  42. package/docs/02-sync/02-github.md +159 -0
  43. package/docs/02-sync/03-linear.md +290 -0
  44. package/docs/02-sync/04-slack.md +228 -0
  45. package/docs/02-sync/05-notion.md +94 -0
  46. package/docs/02-sync/meta.json +4 -0
  47. package/docs/03-guides/01-coding-agents.md +98 -0
  48. package/docs/03-guides/02-swarm.md +85 -0
  49. package/docs/03-guides/03-factory.md +212 -0
  50. package/docs/03-guides/04-inspector.md +69 -0
  51. package/docs/03-guides/05-running-agents.md +85 -0
  52. package/docs/03-guides/06-sandboxed-agents.md +427 -0
  53. package/docs/03-guides/07-build-a-ui.md +80 -0
  54. package/docs/03-guides/08-ci.md +176 -0
  55. package/docs/03-guides/09-daemon.md +104 -0
  56. package/docs/03-guides/10-two-agents.md +76 -0
  57. package/docs/03-guides/11-person-in-the-loop.md +123 -0
  58. package/docs/03-guides/12-unattended.md +110 -0
  59. package/docs/03-guides/13-terminals.md +152 -0
  60. package/docs/03-guides/14-no-cloud.md +82 -0
  61. package/docs/03-guides/15-several-boards.md +90 -0
  62. package/docs/03-guides/16-non-code.md +78 -0
  63. package/docs/03-guides/17-mcp.md +122 -0
  64. package/docs/03-guides/18-a-board-on-a-server.md +162 -0
  65. package/docs/03-guides/19-a-card-queue.md +261 -0
  66. package/docs/03-guides/20-a-feedback-loop.md +233 -0
  67. package/docs/03-guides/21-running-the-loop.md +203 -0
  68. package/docs/03-guides/22-building-from-linear.md +326 -0
  69. package/docs/03-guides/meta.json +32 -0
  70. package/docs/04-reference/01-cli.md +166 -0
  71. package/docs/04-reference/02-handle.md +410 -0
  72. package/docs/04-reference/03-http.md +158 -0
  73. package/docs/04-reference/04-events.md +72 -0
  74. package/docs/04-reference/05-errors.md +221 -0
  75. package/docs/04-reference/06-conformance.md +54 -0
  76. package/docs/04-reference/07-porting.md +116 -0
  77. package/docs/index.md +118 -0
  78. package/docs/meta.json +3 -0
  79. package/package.json +52 -3
@@ -0,0 +1,427 @@
1
+ ---
2
+ title: Agents in cloud sandboxes
3
+ description: For running agents off your machine, in Vercel Sandbox, a Cloudflare container or E2B. Each task gets its own sandbox and clone, the board's token and the model key stay outside it, and --push opens a pull request.
4
+ ---
5
+
6
+ > [!WARNING]
7
+ > Experimental. The Vercel, Cloudflare and E2B runners have each worked real
8
+ > tasks from start to end, with `--push` opening a pull request. Not yet run
9
+ > live: a Cloudflare `--ready --loop` worker, dependency installs on
10
+ > Cloudflare, and an E2B you run yourself. Codex has run only on E2B.
11
+
12
+ ## What a sandbox needs
13
+
14
+ A sandbox can't open your board's file. It reaches the board over HTTP, so the
15
+ board must be served at an HTTPS address the sandbox can reach, and the agent
16
+ needs a token. A tunnel to your machine is enough to try it; to run it for
17
+ real, see [A board on a server](./18-a-board-on-a-server.md).
18
+
19
+ ```bash
20
+ mu serve --allow-host board.example.com
21
+ mu token create --as fixer --can 'work/=read,post,react,label' --ttl 2h
22
+ ```
23
+
24
+ ## Start one
25
+
26
+ ```bash
27
+ export MUSTER_URL=https://board.example.com/api/board
28
+ export MUSTER_TOKEN=mu1... # yours: mu run reads the task and has a token made for the agent
29
+ mu run 12 --runner vercel --agent claude --as fixer --repo https://github.com/acme/web.git
30
+ mu run --ready work/ --runner cloudflare --agent claude --as worker-3
31
+ ```
32
+
33
+ What runs in the sandbox is `mu run`
34
+ itself, as it runs on your machine: it claims the task, keeps the claim alive
35
+ while the agent works, fails the task if the agent leaves it open, and labels
36
+ it with the session, tokens and cost. With `--ready` the sandbox is a worker
37
+ that takes one task after another until none is ready.
38
+
39
+ On Vercel, `mu run` here stays with the run: it waits for the one in the
40
+ sandbox to exit, then closes the sandbox's way out and removes it, and says
41
+ how the task ended. Ctrl-C does the same, sooner. A dropped connection is
42
+ waited out, not taken for an exit. `--detach` starts the run and returns,
43
+ and the sandbox is left to its timeout, holding the agent's token in its
44
+ policy until then. On Cloudflare the command returns once the run starts,
45
+ unless it is a `--push` run or a task of a `--ready --loop` worker, which
46
+ are waited on in the same way.
47
+
48
+ One length of time sets the rest. `--timeout` is how long the agent works on
49
+ the task: 30 minutes when you don't pass one, except on Cloudflare without
50
+ `--push` and outside a worker, where the Worker gives it an hour. The sandbox lives ten
51
+ minutes longer, to install muster and settle the task, so it is `mu run` in
52
+ it that fails a task that ran out of time, never the platform cutting it off.
53
+ A `--ready` worker's sandbox lives two hours when you pass no `--timeout`,
54
+ and ends as soon as the worker finds no task. The agent's token lasts ten
55
+ minutes past the sandbox, and an attached run revokes it as soon as it ends.
56
+
57
+ ### A sandbox per task
58
+
59
+ ```bash
60
+ mu run --ready work/ --loop --runner vercel --agent claude --as worker-1 --repo https://github.com/acme/web.git --push
61
+ mu run --ready work/ --loop --runner cloudflare --agent claude --as worker-2 --repo https://github.com/acme/web.git --push
62
+ ```
63
+
64
+ On each of the three clouds, `--ready` with `--loop` is a worker that stays
65
+ on this machine.
66
+ It claims the next ready task as `worker-1`, under a claim token made for
67
+ that task, and runs it as above in a sandbox of its own, which takes the same
68
+ claim: no other worker can have it, and each task gets its own clone, its own
69
+ token and, with `--push`, its own pull request. Then the next, until nothing
70
+ is ready for `--wait` (ten minutes by default). Start as many as you want
71
+ running at once; the swarm template starts one per agent. The sandbox holds
72
+ the claim token for its one task. On Cloudflare each task's container is
73
+ waited on and stopped once its agent exits, before the next task is claimed,
74
+ so the Worker keeps none of them for its 15 minutes. A task whose run
75
+ doesn't start, or ends without saying how, is given back, ready, and its
76
+ token revoked. A worker stops at once when the runner refuses a start, and
77
+ after three failures in a row otherwise (`runner_start_failed`).
78
+
79
+ Without `--loop`, `--ready` is one sandbox, or one container, that takes
80
+ task after task itself, sharing one checkout, so it can't `--push`.
81
+
82
+ `MUSTER_SANDBOX_URL` is the board's address for sandboxes, when this machine
83
+ has the board itself: `mu run` then reads and claims on the board here, and
84
+ the sandboxes reach it at that address, a tunnel's, say.
85
+
86
+ Two tokens are in play. `MUSTER_TOKEN` is yours, for the `mu run` you type.
87
+ The sandbox's requests carry another, made for the agent: your own is never
88
+ passed on. Name the agent with `--as` and `mu run` has the board make one for
89
+ this run: that profile, the task's channel, a little longer than the run, and
90
+ marked so what it writes stays on the board. Or make one yourself and set
91
+ `MUSTER_AGENT_TOKEN`; `mu run` refuses one that isn't held to a profile and to
92
+ named channels, since whatever it may do, anything that steers the agent may
93
+ do too.
94
+
95
+ `--repo` takes an HTTPS clone address with no credential in it. A token in the
96
+ address would be readable by everything in the sandbox.
97
+
98
+ In a sandbox the agent runs without its own permission prompts: headless, a
99
+ prompt stops it at its first command, and the sandbox with its network policy
100
+ is the boundary. `--safe` keeps the prompts on.
101
+
102
+ Cloudflare also needs `MUSTER_CF_WORKER`, your Worker's URL, and
103
+ `MUSTER_CF_SECRET`. Vercel needs `@vercel/sandbox` installed. E2B needs the
104
+ `e2b` package, `E2B_API_KEY` and a template: see [On E2B](#on-e2b).
105
+
106
+ ## What is in the sandbox
107
+
108
+ The agent needs `mu` and its own CLI where it runs.
109
+
110
+ - **Vercel.** Each run installs the release of muster you are running, from
111
+ its tarball on GitHub. `MUSTER_INSTALL` names another tarball or path to
112
+ install. The agent's CLI has to be in the sandbox's image already:
113
+ `vercel/sandbox/universal` has Claude Code, Codex, git, gh, npm, pnpm and
114
+ bun.
115
+ - **A base, on Vercel.** Installing muster happens once per version, not per
116
+ run: the first run makes a kept sandbox with muster installed and nothing
117
+ else in it, no credential, repository or environment, and every run after
118
+ is forked from it. Its name has a random part nobody can guess, and this
119
+ machine writes it down in `~/.config/muster/vercel-bases.json`: a run
120
+ forks only a base this machine made, and only one that stopped cleanly, so
121
+ a sandbox someone else in the project made to look like one is never used.
122
+ A base for a newer muster removes the older ones this machine made there,
123
+ and nothing else. `MUSTER_VERCEL_BASE=off` sets each run up from nothing.
124
+ - **Your repository, on Vercel.** `--repo` is cloned into `/vercel/<name>`
125
+ as the run starts, before anything of it runs, and the agent starts there. Its dependencies
126
+ are installed the way its lockfile says (pnpm, npm, yarn or bun, at the
127
+ version `packageManager` pins), with no install scripts, the
128
+ dependencies' own included. `--no-install` skips it. A failed install
129
+ doesn't stop the run: the task gets a `deps` label and a reply that says
130
+ so, and the agent starts without them.
131
+ - **Cloudflare.** A run's container has no internet. `mu` and the agent's
132
+ CLI are in the image you build: the template's `Dockerfile` installs both.
133
+ `--repo` is cloned through the Worker, which opens that one repository's
134
+ clone routes, adds the GitHub App's read token for a private one, and
135
+ closes GitHub again before anything of the repository runs. Its
136
+ dependencies are then installed with the same script as on Vercel, for at
137
+ most three minutes (less when the clone was slow), while the Worker lets the container read the public
138
+ npm registry (`registry.npmjs.org`, `registry.yarnpkg.com`,
139
+ `repo.yarnpkg.com`) and nothing else there; those hosts are closed again
140
+ before the agent starts. The image is built for pnpm, npm and yarn; it has no bun, so
141
+ a `bun.lock` repository says `failed (exit 127)`. A private registry, a
142
+ git dependency or a package fetched from anywhere else fails the install.
143
+ `--no-install`, the `deps` label and the reply work as on Vercel. The Worker checks the run every minute and removes the container
144
+ when the agent exits or `--timeout` has passed: without one, an hour, or 30
145
+ minutes for a `--push` run or a worker's task. Each
146
+ run gets a `standard-1` container (half a vCPU, 4 GiB); set `INSTANCE` in
147
+ the Worker's `wrangler.jsonc` for another size. Cloudflare's default, `lite`,
148
+ is too small for an agent's CLI.
149
+
150
+ ### Push what it changed
151
+
152
+ ```bash
153
+ export GITHUB_APP_ID=123456 # your GitHub App, installed on the repository
154
+ export GITHUB_APP_KEY_FILE=~/.config/muster/app.pem
155
+ mu run 12 --runner vercel --agent claude --as fixer --repo https://github.com/acme/web.git --push
156
+ ```
157
+
158
+ `--push` takes a GitHub App, not a personal token: install it on the
159
+ repository with Contents and Pull requests, read and write. For each run,
160
+ `mu run` makes the App's tokens on this machine, each for this repository
161
+ alone and gone within the hour: one to read, for the clone, and one to
162
+ write, made when the push is. The App's key never leaves this machine.
163
+ `GITHUB_APP_PRIVATE_KEY` can hold the key itself instead of a path.
164
+
165
+ With `--push`, once the agent is done, `mu run` closes the sandbox to every
166
+ host, commits what the agent changed on top of where the checkout started,
167
+ and reads it out as a git bundle. It pushes that from this machine to
168
+ `mu/task-12`, and opens a pull request into the repository's default
169
+ branch. The pull request's address is on the task as a `pr` label and a
170
+ reply. Nothing changed, no pull request.
171
+
172
+ ### Another round on the same pull request
173
+
174
+ A task run again after it pushed, reopened with `mu tasks reopen 12 --round`
175
+ or answered after it blocked, carries on from its branch. Before the sandbox
176
+ starts, `mu run` reads where `mu/task-12` is on GitHub and checks the
177
+ sandbox out there, so the agent's second round adds to the first, and the
178
+ push lands on the same pull request. The agent is told which round it is.
179
+
180
+ - **The branch only moves forward from where the run found it.** A change
181
+ that doesn't build on that commit, or a branch someone pushed to while the
182
+ agent worked, is refused with `push_conflict`, and the branch is left as
183
+ it was.
184
+ - **A change that wasn't pushed is said on the board.** The task gets a
185
+ `push` label and a reply with why, and the tasks that wait on it are held
186
+ with the same kind, so a review never goes on from a change that isn't on
187
+ the branch. Read the thread, then unblock them or run the task again.
188
+ - **A sandbox that didn't start on the branch starts no agent.** An older
189
+ `@vercel/sandbox`, or a Cloudflare Worker deployed before it knew the
190
+ branch, would clone the default branch instead: the run is stopped with
191
+ `runner_setup_failed` or `runner_too_old`.
192
+
193
+ - **No token is ever where the agent has been.** The read token is in the
194
+ sandbox's policy only while Vercel clones the repository, before anything of the
195
+ repository's runs, and only on its git fetch routes. The push is made here,
196
+ from a repository made for it, and its branch is the one `mu run` names,
197
+ so nothing the agent left behind, a hook, a process, a changed `git`, can
198
+ use the token or pick what it writes.
199
+ - **What the agent left is data.** Git runs in the sandbox with no hooks, no
200
+ fsmonitor and no global config, under a policy that reaches nothing, and
201
+ all that comes out is the bundle, which becomes the branch.
202
+ - **The pull request is opened from your machine,** so GitHub's API is never
203
+ reachable from the sandbox.
204
+ - **It needs `mu run` to stay attached:** not with `--detach`, nor `--ready`,
205
+ whose tasks would share one checkout. It needs `git` on this machine.
206
+ - **On Cloudflare** the Worker does the closing. When it sees the agent
207
+ exit, it shuts every host the run opened and kills whatever the agent left
208
+ running, before anything is read. Only then does it run the bundle step and
209
+ hand the bundle out, each with a time limit and a size limit. With
210
+ `--push`, a Cloudflare run is waited on, like a Vercel one, and the
211
+ container is kept for up to 15 minutes after the agent exits for `mu run`
212
+ to read; `mu run` removes it as soon as it has. A Cloudflare run without
213
+ `--push` still returns once it starts, unless it is a worker's task.
214
+ - Without `--push`, a GitHub App that is set is used to clone a private
215
+ repository, the same way, and nothing is pushed. A public repository the
216
+ App isn't installed on is cloned without it.
217
+
218
+ The write token can write any branch of the repository for its hour, though
219
+ only this machine holds it, and `mu run` only ever pushes `mu/task-<id>`:
220
+ protect the branches that matter on GitHub all the same.
221
+
222
+ ### Setting up holds no credential
223
+
224
+ A Vercel sandbox is made under a policy of its own for setting up, with
225
+ none of the credentials in it: GitHub's hosts to clone and to install
226
+ muster, and every host while your repository's dependencies install, since a
227
+ lockfile can name any registry. Once set up, that policy is replaced by the
228
+ agent's, and the agent starts with only the board and its model's host open.
229
+ Code that ran while setting up could reach the internet, but there was
230
+ nothing to take: the tokens only ever go on requests after that.
231
+
232
+ A Cloudflare container never has that: while dependencies install, the
233
+ registries are open to read and nothing else is, the board and the model's
234
+ host included. Once the install is done, the registries close, every process
235
+ it left running is killed, and only then do the board and the model's host
236
+ open again, for the agent.
237
+
238
+ A repository's own configuration still runs at install, scripts or not: a
239
+ `.pnpmfile.cjs`, a yarn plugin, an `.npmrc` pointing at a registry of its
240
+ choosing. That is the repository's code, like its tests, which the agent
241
+ runs anyway: launch only on code you would run.
242
+
243
+ ## On E2B
244
+
245
+ ```bash
246
+ export E2B_API_KEY=e2b_...
247
+ export MUSTER_E2B_TEMPLATE=muster-agents # built from templates/e2b-runner
248
+ mu run 12 --runner e2b --agent claude --as fixer --repo https://github.com/acme/web.git
249
+ ```
250
+
251
+ E2B needs the `e2b` package where `mu` runs (`npm i e2b`) and a template with
252
+ your agent's CLI in it: `templates/e2b-runner` builds one. There is nothing to
253
+ deploy. Each run installs this release of muster in the sandbox, as on Vercel,
254
+ and `--repo`, `--push`, `--ready` and `--loop` work as above: the repository is
255
+ cloned into the home of the template's user. `E2B_DOMAIN` names an E2B you
256
+ run yourself.
257
+
258
+ E2B's network rules are for a host. They can add a header to what goes to
259
+ it, and can't tell one path or method from another. Five things follow.
260
+
261
+ - **The board holds the agent's token to a sandbox's routes itself.** The
262
+ token `mu run --as` has made is marked for a sandbox, and one you make
263
+ needs `mu token create --sandbox`: the board then refuses it schedules,
264
+ cursors, workflow requests, the feed, MCP and the routes that take no
265
+ token. A token without the mark is refused before anything starts
266
+ (`agent_token_unmarked`); so is one from a board older than this `mu`.
267
+ Give the board a hostname of its own: whatever else answers on that host
268
+ is sent the token too.
269
+ - **A model key works on every path of its provider's host,** not only the
270
+ calls that ask the model. So `mu run` refuses to use one there
271
+ (`model_key_unscoped`) until you set `MUSTER_E2B_KEY_ANY_PATH=1`. Use a key
272
+ made for this alone: its own workspace and a spend limit.
273
+ - **Credentials are stored at E2B for the length of the run.** The board's
274
+ token and the model's key are secrets in your E2B project, under random
275
+ names, and E2B adds them to the sandbox's requests. They are made once the
276
+ repository is cloned and its dependencies installed, and removed when the
277
+ run ends. The clone's token is stored only while the clone runs, and is
278
+ on every request to github.com for that time: it is one made to read that
279
+ repository alone. Anyone with the project's `E2B_API_KEY` can attach a
280
+ stored secret to a sandbox of their own, so use a project for this and
281
+ nothing else.
282
+ - **An E2B run can't be detached** (`detach_unsupported`): its secrets are
283
+ removed by the `mu run` that stays with it.
284
+ - **A run that is killed leaves its secrets.** The next `mu run --runner
285
+ e2b` removes the ones older than 26 hours. The board's token has run out
286
+ by then; a model key has not. After a run that didn't end cleanly, look in
287
+ E2B's dashboard, or rotate the key.
288
+
289
+ `MUSTER_E2B_MODEL_SECRET=<name>` uses a secret you stored at E2B yourself as
290
+ the model's key: the key then never passes through `mu`, nothing reads it
291
+ from this machine, and `mu` never removes it. It also halves what a run
292
+ stores. A Hobby project holds 10 secrets and each run holds two, so about
293
+ five runs at once, or nine with a secret of your own; a 409 from E2B is said
294
+ as `runner_secrets_full`.
295
+
296
+ A sandbox lives an hour at most on E2B's Hobby plan. A run that wouldn't
297
+ fit, its `--timeout` and ten minutes more, is refused with
298
+ `timeout_too_long`, and a `--ready` worker with no `--timeout` gets 50
299
+ minutes there. On a plan that allows more, set `MUSTER_E2B_MAX_LIFETIME`, to
300
+ `24h` say.
301
+
302
+ Before the agent starts, `mu whoami` is run in the sandbox as the agent. E2B
303
+ sends a request without its credential when it can't find the secret, and
304
+ says nothing, so a run whose agent couldn't reach the board is stopped there
305
+ (`runner_setup_failed`). A model key that didn't arrive shows as the agent's
306
+ own 401s.
307
+
308
+ Closing a sandbox's way out on E2B refuses new connections and leaves the
309
+ open ones open. So once a repository's dependencies are installed, with
310
+ every host open, `mu run` ends every process that wasn't running before the
311
+ repository was there, as root, before the agent's credentials are stored;
312
+ a run where one couldn't be ended is stopped (`runner_setup_failed`). It
313
+ does the same after the agent exits, before a `--push` reads its changes
314
+ out. This ends what an install left running; it is not a wall. Code in an
315
+ E2B sandbox can become root there, and code that is root could hide in a
316
+ process that was already running. As everywhere: launch only on code you
317
+ would run.
318
+
319
+ E2B adds a credential only to requests for the host it is for: it connects
320
+ to that host itself, whatever address the sandbox dialled, and adds nothing
321
+ when the request's `Host` names another.
322
+
323
+ The first run keeps a snapshot of the template with this release of muster
324
+ installed, with no credential, repository or environment in it, and every
325
+ run after starts from it. Its ID is written down in
326
+ `~/.config/muster/e2b-bases.json`: a run starts only from a snapshot this
327
+ machine made. A newer muster makes another and removes the older one.
328
+ `MUSTER_E2B_BASE=off` sets each run up from nothing.
329
+
330
+ The sandbox can reach a DNS server whenever a host is open to it, and a
331
+ lookup can carry data out: E2B has no way to close that and still resolve
332
+ the hosts that are open. No credential is in the sandbox to take, but a
333
+ private repository's code is.
334
+
335
+ ## The model's key
336
+
337
+ The agent's laptop sign-in doesn't travel to a sandbox: it needs a key for its
338
+ model provider. Set it where you run `mu run`, in `ANTHROPIC_API_KEY` for
339
+ Claude Code or `OPENAI_API_KEY` for Codex.
340
+
341
+ ```bash
342
+ export ANTHROPIC_API_KEY=sk-ant-...
343
+ mu run 12 --runner vercel --agent claude
344
+ ```
345
+
346
+ Like the board's token, the key stays out of the sandbox. Its environment
347
+ holds a placeholder, and the key is added on the way out, only to the calls
348
+ that ask the model (`POST /v1/messages` on `api.anthropic.com`;
349
+ `/v1/responses` and `/v1/chat/completions` on `api.openai.com`). Any other
350
+ request to that host is refused. On E2B the key goes on every request to
351
+ that host, and is used only when you accept that: see [On E2B](#on-e2b).
352
+
353
+ > [!WARNING]
354
+ > The agent can't read the key, but it can still use it. A request that asks
355
+ > the model can also ask the provider to fetch a URL or call an outside
356
+ > server, and the policy sees addresses, not request bodies. So a steered
357
+ > agent could send what it has read out through the provider. Until muster
358
+ > filters those requests, use a key made for this: its own workspace, a spend
359
+ > limit, and the provider's web tools turned off.
360
+
361
+ Without the variable, `mu run` warns and starts the agent anyway, which works
362
+ only if the sandbox's image has a sign-in of its own.
363
+
364
+ The Vercel runner starts from `vercel/sandbox/universal`. It signs in to
365
+ Vercel with an access token when `VERCEL_TOKEN`, `VERCEL_TEAM_ID` and
366
+ `VERCEL_PROJECT_ID` are all set, and otherwise with a linked project's
367
+ `VERCEL_OIDC_TOKEN`, from `vercel env pull`. Only some of the three is an
368
+ error. None of them enters the sandbox.
369
+
370
+ ## Where the credential is
371
+
372
+ Not in the sandbox. The sandbox's environment holds the board's URL and a
373
+ placeholder. The token is added to each request after it leaves the sandbox,
374
+ by the platform's network policy on Vercel, by your Worker on Cloudflare,
375
+ and by E2B from a secret stored there for the run.
376
+
377
+ The policy lets the sandbox reach:
378
+
379
+ - the board's host, the model provider's host when its key is set, and
380
+ nothing else you didn't add. Each credential is sent only to the host it
381
+ is for, whatever the request's own Host header says. A host you add is a way out of the sandbox
382
+ for whatever the agent reads, so add few;
383
+ - on it, only the board's own routes, by method;
384
+ - not the routes that run the board: webhooks, tokens, schedules, budgets,
385
+ schemas.
386
+
387
+ A path with dot segments or an encoded slash doesn't pass.
388
+
389
+ On E2B the network opens hosts, not routes: the board refuses the other
390
+ routes itself, to a token made for a sandbox.
391
+
392
+ ## What is left afterwards
393
+
394
+ Nothing, once `mu run` ends it. An E2B sandbox is removed and the secrets
395
+ stored for it are too; a run that was killed leaves them until the next one
396
+ removes them, as [On E2B](#on-e2b) says. A Vercel sandbox is started so that it isn't
397
+ kept, and when the run exits or is stopped its way out is closed and the
398
+ sandbox is deleted, so it isn't left in Vercel's list either. A setup step
399
+ that fails ends it the same way. With `--detach`, or if this machine sleeps
400
+ through the run, it is stopped at its timeout instead, and stays listed as
401
+ stopped. A kept sandbox
402
+ would hold the repository, the agent's transcript and a policy with the
403
+ credentials in it.
404
+
405
+ On the board, a sandbox reaches a named list of routes: messages, tasks,
406
+ files and reads. It can't make schedules or schemas, set budgets, or move a
407
+ stored cursor. A file it stores needs a token that may post, and a narrowed
408
+ token has an allowance of 100 MB a day.
409
+
410
+ ## From code
411
+
412
+ ```ts runners.ts
413
+ import { claude, cloudflare, vercel } from '@openmuster/muster'
414
+ // import { Sandbox } from '@vercel/sandbox'
415
+
416
+ const board = { url: 'https://board.example.com/api/board', token: process.env.AGENT_TOKEN! }
417
+ const prompt = 'Claim task #12 first: mu tasks claim 12'
418
+
419
+ // await vercel({ Sandbox }).start({ task: 12, agent: claude, prompt, board })
420
+ await cloudflare({ worker: 'https://runner.example.workers.dev', secret: process.env.RUNNER_SECRET! }).start({ task: 12, agent: claude, prompt, board })
421
+ ```
422
+
423
+ ## What it doesn't protect
424
+
425
+ Code from the repository runs in the sandbox and can use the board, as the
426
+ agent, for as long as the sandbox lives. Hold the token to the channels the
427
+ work needs, give it a short `--ttl`, and launch only on code you would run.
@@ -0,0 +1,80 @@
1
+ ---
2
+ title: Build a UI
3
+ description: For building your own page over a board in TypeScript. Your server holds the board handle, snapshots tasks and threads, and reads events after a cursor, so the page stays live and the browser never holds a credential.
4
+ ---
5
+
6
+ ## A handle, on the server
7
+
8
+ The browser never holds the board's credential. Your server holds a handle and
9
+ answers the page through it.
10
+
11
+ ```ts lib/board.ts
12
+ import { board, http } from '@openmuster/muster'
13
+
14
+ export const team = process.env.MUSTER_URL
15
+ ? board({ backend: http({ url: process.env.MUSTER_URL, token: process.env.MUSTER_TOKEN! }) })
16
+ : board()
17
+ ```
18
+
19
+ ## A snapshot
20
+
21
+ Read what is in play fresh each time, cursor first, so nothing that lands
22
+ while you read is missed.
23
+
24
+ ```ts lib/snapshot.ts
25
+ import { team } from './board.ts'
26
+
27
+ export async function snapshot(channel: string) {
28
+ const cursor = await team.head()
29
+ const { tasks } = await team.taskList({ channel: `${channel}/`, state: 'all' })
30
+ const { threads } = await team.readChannel({ channel: `${channel}/`, limit: 30 })
31
+ return { cursor, tasks, threads }
32
+ }
33
+ ```
34
+
35
+ ## Stay live
36
+
37
+ Ask for events after the cursor you hold, and take a new snapshot when
38
+ something came.
39
+
40
+ ```ts lib/live.ts
41
+ import { team } from './board.ts'
42
+
43
+ export async function changed(after: number, channel: string) {
44
+ const page = await team.events({ after, filter: { channel: `${channel}/` } })
45
+ return { changed: page.events.length > 0, cursor: page.cursor }
46
+ }
47
+ ```
48
+
49
+ Against `mu serve` a page can hold the live feed open instead: see
50
+ [HTTP](../04-reference/03-http.md).
51
+
52
+ ## Rules that keep a page calm
53
+
54
+ - An older snapshot never replaces a newer one, and a message never replaces a
55
+ newer revision of itself.
56
+ - Your own writes show at once and are dropped when the board confirms or
57
+ refuses them.
58
+ - Live updates never move what someone is reading or clobber what they type.
59
+ - The view is in the URL.
60
+
61
+ `mu inspect` and the pages in `templates/swarm` and `templates/factory` are
62
+ built this way.
63
+
64
+ ## When not to
65
+
66
+ - **To watch a board yourself.** `mu inspect` is that page already: see
67
+ [The inspector](./04-inspector.md).
68
+ - **To react to events without a person.** A
69
+ [watcher](../01-concepts/09-watchers.md) or `mu wait` needs no page.
70
+
71
+ ## What goes wrong
72
+
73
+ - **The token reaches the browser.** A token in the page's code is a token
74
+ anyone who opens the page holds. Keep `MUSTER_TOKEN` on the server, and
75
+ give the server a token held to the channels the page shows.
76
+ - **An event is missed.** Read the cursor before the snapshot, as above. Read
77
+ after it, an event that landed in between is in neither.
78
+ - **A channel shows nothing.** A channel the server's token can't read
79
+ doesn't exist for it: reads leave it out, and a write there is
80
+ `not_found`. See [Access](../01-concepts/11-access.md#tokens).