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

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