@parcha/agentrun-serve 0.0.0-bootstrap.0 → 0.1.0-beta.29

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 (229) hide show
  1. package/CHANGELOG.md +560 -0
  2. package/LICENSE +202 -0
  3. package/NOTICE +5 -0
  4. package/README.md +1724 -0
  5. package/dist/adapters.d.ts +205 -0
  6. package/dist/adapters.js +459 -0
  7. package/dist/agents.d.ts +124 -0
  8. package/dist/agents.js +302 -0
  9. package/dist/app.d.ts +7 -0
  10. package/dist/app.js +324 -0
  11. package/dist/bound-files.d.ts +4 -0
  12. package/dist/bound-files.js +164 -0
  13. package/dist/box/record.d.ts +6 -0
  14. package/dist/box/record.js +41 -0
  15. package/dist/box/sweep.d.ts +53 -0
  16. package/dist/box/sweep.js +193 -0
  17. package/dist/box-image.d.ts +98 -0
  18. package/dist/box-image.js +283 -0
  19. package/dist/box-relay.d.ts +42 -0
  20. package/dist/box-relay.js +222 -0
  21. package/dist/boxes.d.ts +54 -0
  22. package/dist/boxes.js +182 -0
  23. package/dist/cap.d.ts +224 -0
  24. package/dist/cap.js +721 -0
  25. package/dist/catalog.d.ts +20 -0
  26. package/dist/catalog.js +53 -0
  27. package/dist/cli.d.ts +2 -0
  28. package/dist/cli.js +167 -0
  29. package/dist/coding-tools.d.ts +31 -0
  30. package/dist/coding-tools.js +81 -0
  31. package/dist/console/THIRD-PARTY-NOTICES.txt +1141 -0
  32. package/dist/console/assets/index-BN7oVcO4.js +445 -0
  33. package/dist/console/assets/index-By-jkqki.css +1 -0
  34. package/dist/console/assets/jetbrains-mono-cyrillic-400-normal-BEIGL1Tu.woff2 +0 -0
  35. package/dist/console/assets/jetbrains-mono-cyrillic-400-normal-CIEtRijs.woff +0 -0
  36. package/dist/console/assets/jetbrains-mono-cyrillic-600-normal-BB5xRk30.woff +0 -0
  37. package/dist/console/assets/jetbrains-mono-cyrillic-600-normal-EVf6-Yzo.woff2 +0 -0
  38. package/dist/console/assets/jetbrains-mono-cyrillic-ext-400-normal-BHyURHCj.woff +0 -0
  39. package/dist/console/assets/jetbrains-mono-cyrillic-ext-400-normal-C_uLvvQ5.woff2 +0 -0
  40. package/dist/console/assets/jetbrains-mono-cyrillic-ext-600-normal-Dj6eZy5f.woff2 +0 -0
  41. package/dist/console/assets/jetbrains-mono-cyrillic-ext-600-normal-DpeVePZf.woff +0 -0
  42. package/dist/console/assets/jetbrains-mono-greek-400-normal-C190GLew.woff2 +0 -0
  43. package/dist/console/assets/jetbrains-mono-greek-400-normal-CNojz0t3.woff +0 -0
  44. package/dist/console/assets/jetbrains-mono-greek-600-normal-3KAm9r92.woff +0 -0
  45. package/dist/console/assets/jetbrains-mono-greek-600-normal-H7WoG9Et.woff2 +0 -0
  46. package/dist/console/assets/jetbrains-mono-latin-400-normal-B11XCQ5g.woff +0 -0
  47. package/dist/console/assets/jetbrains-mono-latin-400-normal-V6pRDFza.woff2 +0 -0
  48. package/dist/console/assets/jetbrains-mono-latin-600-normal-C8RAYTDA.woff2 +0 -0
  49. package/dist/console/assets/jetbrains-mono-latin-600-normal-DXv3JcnD.woff +0 -0
  50. package/dist/console/assets/jetbrains-mono-latin-ext-400-normal-Bc8Ftmh3.woff2 +0 -0
  51. package/dist/console/assets/jetbrains-mono-latin-ext-400-normal-DHMOLxAi.woff +0 -0
  52. package/dist/console/assets/jetbrains-mono-latin-ext-600-normal-BfB_LPfz.woff2 +0 -0
  53. package/dist/console/assets/jetbrains-mono-latin-ext-600-normal-DiQlUoE6.woff +0 -0
  54. package/dist/console/assets/jetbrains-mono-vietnamese-400-normal-BeU3T8wf.woff +0 -0
  55. package/dist/console/assets/jetbrains-mono-vietnamese-400-normal-ByoDsISC.woff2 +0 -0
  56. package/dist/console/assets/jetbrains-mono-vietnamese-600-normal-CSpzN4cI.woff +0 -0
  57. package/dist/console/assets/jetbrains-mono-vietnamese-600-normal-Dtizs43-.woff2 +0 -0
  58. package/dist/console/assets/schibsted-grotesk-latin-400-normal-Cph9ettZ.woff2 +0 -0
  59. package/dist/console/assets/schibsted-grotesk-latin-400-normal-DfGZKnlb.woff +0 -0
  60. package/dist/console/assets/schibsted-grotesk-latin-600-normal-BGBUNdzT.woff2 +0 -0
  61. package/dist/console/assets/schibsted-grotesk-latin-600-normal-COje25QW.woff +0 -0
  62. package/dist/console/assets/schibsted-grotesk-latin-ext-400-normal-4l4lq8zr.woff2 +0 -0
  63. package/dist/console/assets/schibsted-grotesk-latin-ext-400-normal-BGzXWJeR.woff +0 -0
  64. package/dist/console/assets/schibsted-grotesk-latin-ext-600-normal-8_E36CQj.woff2 +0 -0
  65. package/dist/console/assets/schibsted-grotesk-latin-ext-600-normal-C27an7Zc.woff +0 -0
  66. package/dist/console/index.html +15 -0
  67. package/dist/daytona-api.d.ts +21 -0
  68. package/dist/daytona-api.js +101 -0
  69. package/dist/decision-rows.d.ts +11 -0
  70. package/dist/decision-rows.js +116 -0
  71. package/dist/decisions.d.ts +94 -0
  72. package/dist/decisions.js +184 -0
  73. package/dist/effort-guidance.d.ts +5 -0
  74. package/dist/effort-guidance.js +14 -0
  75. package/dist/environment.d.ts +5 -0
  76. package/dist/environment.js +11 -0
  77. package/dist/errors.d.ts +72 -0
  78. package/dist/errors.js +66 -0
  79. package/dist/exa-keyless.d.ts +35 -0
  80. package/dist/exa-keyless.js +202 -0
  81. package/dist/fetch-page.d.ts +114 -0
  82. package/dist/fetch-page.js +182 -0
  83. package/dist/files.d.ts +60 -0
  84. package/dist/files.js +153 -0
  85. package/dist/grade.d.ts +96 -0
  86. package/dist/grade.js +348 -0
  87. package/dist/graph-view.d.ts +100 -0
  88. package/dist/graph-view.js +212 -0
  89. package/dist/harness-app.d.ts +38 -0
  90. package/dist/harness-app.js +626 -0
  91. package/dist/harness.d.ts +53 -0
  92. package/dist/harness.js +74 -0
  93. package/dist/home-path.d.ts +27 -0
  94. package/dist/home-path.js +78 -0
  95. package/dist/host-tools.d.ts +20 -0
  96. package/dist/host-tools.js +140 -0
  97. package/dist/host.d.ts +39 -0
  98. package/dist/host.js +81 -0
  99. package/dist/hosted-search.d.ts +27 -0
  100. package/dist/hosted-search.js +129 -0
  101. package/dist/import-sources.d.ts +104 -0
  102. package/dist/import-sources.js +629 -0
  103. package/dist/import-summary.d.ts +25 -0
  104. package/dist/import-summary.js +75 -0
  105. package/dist/import-worker.d.ts +26 -0
  106. package/dist/import-worker.js +41 -0
  107. package/dist/import.d.ts +145 -0
  108. package/dist/import.js +1221 -0
  109. package/dist/index.d.ts +7 -0
  110. package/dist/index.js +6 -0
  111. package/dist/key-check.d.ts +36 -0
  112. package/dist/key-check.js +108 -0
  113. package/dist/key-refusal.d.ts +51 -0
  114. package/dist/key-refusal.js +187 -0
  115. package/dist/learn/check.d.ts +99 -0
  116. package/dist/learn/check.js +259 -0
  117. package/dist/learn/grade.d.ts +79 -0
  118. package/dist/learn/grade.js +433 -0
  119. package/dist/learn/index.d.ts +7 -0
  120. package/dist/learn/index.js +11 -0
  121. package/dist/learn/invisible.d.ts +5 -0
  122. package/dist/learn/invisible.js +42 -0
  123. package/dist/learn/notes.d.ts +59 -0
  124. package/dist/learn/notes.js +146 -0
  125. package/dist/learn/reflect.d.ts +49 -0
  126. package/dist/learn/reflect.js +167 -0
  127. package/dist/learn/secrets.d.ts +18 -0
  128. package/dist/learn/secrets.js +111 -0
  129. package/dist/learn/skills.d.ts +84 -0
  130. package/dist/learn/skills.js +198 -0
  131. package/dist/learning-routes.d.ts +196 -0
  132. package/dist/learning-routes.js +609 -0
  133. package/dist/learning-run.d.ts +304 -0
  134. package/dist/learning-run.js +797 -0
  135. package/dist/learning-words.d.ts +73 -0
  136. package/dist/learning-words.js +171 -0
  137. package/dist/learning.d.ts +377 -0
  138. package/dist/learning.js +801 -0
  139. package/dist/llm.d.ts +40 -0
  140. package/dist/llm.js +37 -0
  141. package/dist/llms.txt +37 -0
  142. package/dist/mcp-servers.d.ts +115 -0
  143. package/dist/mcp-servers.js +445 -0
  144. package/dist/mcp.d.ts +51 -0
  145. package/dist/mcp.js +392 -0
  146. package/dist/model.d.ts +184 -0
  147. package/dist/model.js +484 -0
  148. package/dist/monid.d.ts +74 -0
  149. package/dist/monid.js +277 -0
  150. package/dist/openapi/agentrun-v2.openapi.json +4805 -0
  151. package/dist/openapi.d.ts +10 -0
  152. package/dist/openapi.js +1417 -0
  153. package/dist/owner.d.ts +55 -0
  154. package/dist/owner.js +222 -0
  155. package/dist/packs.d.ts +71 -0
  156. package/dist/packs.js +180 -0
  157. package/dist/page.d.ts +32 -0
  158. package/dist/page.js +133 -0
  159. package/dist/paid-calls.d.ts +46 -0
  160. package/dist/paid-calls.js +110 -0
  161. package/dist/pause.d.ts +68 -0
  162. package/dist/pause.js +97 -0
  163. package/dist/pdf-pages.d.ts +44 -0
  164. package/dist/pdf-pages.js +147 -0
  165. package/dist/place.d.ts +46 -0
  166. package/dist/place.js +105 -0
  167. package/dist/print.d.ts +20 -0
  168. package/dist/print.js +29 -0
  169. package/dist/propose.d.ts +38 -0
  170. package/dist/propose.js +82 -0
  171. package/dist/quiet-sqlite-warning.d.ts +1 -0
  172. package/dist/quiet-sqlite-warning.js +14 -0
  173. package/dist/request-start.d.ts +14 -0
  174. package/dist/request-start.js +226 -0
  175. package/dist/result.d.ts +3 -0
  176. package/dist/result.js +5 -0
  177. package/dist/rows.d.ts +46 -0
  178. package/dist/rows.js +121 -0
  179. package/dist/run-box.d.ts +134 -0
  180. package/dist/run-box.js +440 -0
  181. package/dist/run-manifest.d.ts +27 -0
  182. package/dist/run-manifest.js +60 -0
  183. package/dist/runnable.d.ts +80 -0
  184. package/dist/runnable.js +162 -0
  185. package/dist/runs.d.ts +840 -0
  186. package/dist/runs.js +2279 -0
  187. package/dist/secret-cut.d.ts +27 -0
  188. package/dist/secret-cut.js +109 -0
  189. package/dist/secrets.d.ts +50 -0
  190. package/dist/secrets.js +140 -0
  191. package/dist/server-lock.d.ts +44 -0
  192. package/dist/server-lock.js +140 -0
  193. package/dist/server.d.ts +626 -0
  194. package/dist/server.js +1756 -0
  195. package/dist/sessions.d.ts +4 -0
  196. package/dist/sessions.js +105 -0
  197. package/dist/skills.d.ts +31 -0
  198. package/dist/skills.js +68 -0
  199. package/dist/stats.d.ts +101 -0
  200. package/dist/stats.js +82 -0
  201. package/dist/tool-keys.d.ts +151 -0
  202. package/dist/tool-keys.js +273 -0
  203. package/dist/tool-plane.d.ts +143 -0
  204. package/dist/tool-plane.js +242 -0
  205. package/dist/tools.d.ts +147 -0
  206. package/dist/tools.js +253 -0
  207. package/dist/turn-end.d.ts +23 -0
  208. package/dist/turn-end.js +14 -0
  209. package/dist/turns.d.ts +34 -0
  210. package/dist/turns.js +202 -0
  211. package/dist/uploads.d.ts +104 -0
  212. package/dist/uploads.js +474 -0
  213. package/dist/usage.d.ts +29 -0
  214. package/dist/usage.js +58 -0
  215. package/dist/validate.d.ts +55 -0
  216. package/dist/validate.js +175 -0
  217. package/dist/web-fetch.d.ts +64 -0
  218. package/dist/web-fetch.js +262 -0
  219. package/dist/web-search.d.ts +54 -0
  220. package/dist/web-search.js +136 -0
  221. package/dist/webhooks.d.ts +182 -0
  222. package/dist/webhooks.js +487 -0
  223. package/dist/workspace-paths.d.ts +33 -0
  224. package/dist/workspace-paths.js +104 -0
  225. package/dist/workspace.d.ts +88 -0
  226. package/dist/workspace.js +369 -0
  227. package/launcher/agentrun-serve +109 -0
  228. package/package.json +96 -1
  229. package/skills/agentrun-serve/SKILL.md +128 -0
package/README.md ADDED
@@ -0,0 +1,1724 @@
1
+ # @parcha/agentrun-serve
2
+
3
+ AgentRun Server: the Agentrun v2 API on your own machine, or in one container. `agentrun-serve` serves the same `/v2` contract (`agentrun.v2/0`) as the hosted
4
+ API, over one agent store of [`@parcha/pi-durable-agent`](../pi-durable-agent/README.md) in a directory: many agents,
5
+ each with revisions written once (an agentic prompt, or an agentrun-dsl workflow), and every run pinned to the revision
6
+ it ran. Each run is a [`@parcha/pi-durable-disk`](../pi-durable-disk/README.md) run directory beside the store. An SDK
7
+ pointed at it works the way it works against the hosted API; the capabilities document says what this server does not
8
+ offer.
9
+
10
+ Published to npm from the next release (`@latest`): `npx @parcha/agentrun-serve` then starts it with nothing else installed, its
11
+ console included. Until then, run it from a checkout (below) or the container.
12
+
13
+ ## Quick start (no key, no network)
14
+
15
+ Node 22.19 or later on 22, or 24.2 or later. In a checkout of this repository:
16
+
17
+ ```sh
18
+ npm ci --ignore-scripts && npm run build
19
+ cat > faux.mjs <<'JS'
20
+ export default (context, faux) => faux.message("The answer is 42.");
21
+ JS
22
+ node packages/serve/dist/cli.js --faux faux.mjs
23
+ ```
24
+
25
+ Installed, `agentrun-serve` is a launcher that needs a POSIX `sh` with a builtin `printf` (Linux, macOS; not Windows). It hands the server its keys and token over a pipe, so none is in any process's environment, the run's processes included. Started as `node dist/cli.js`, as above, the server reads them from its own environment. `GET /v2/capabilities`' `secrets` says how they are held, and what that does not cover. Started with `npx @parcha/agentrun`, your shell and npm keep the keys you exported in their environment, as they always do; the server itself, and its runs, hold none. For the strictest custody, start this launcher directly, with each key set for that one command and not exported: once the launcher has handed a key to the server, no process holds it in its environment. The launcher takes keys from its environment only, not from a file or standard input.
26
+
27
+ It prints where it listens and, at the start that made it, the token:
28
+
29
+ ```
30
+ agentrun-serve on http://127.0.0.1:7340/v2 (agent store in ~/.local/share/agentrun/agents)
31
+ AGENTRUN_BASE_URL=http://127.0.0.1:7340/v2
32
+ AGENTRUN_API_KEY=ar_local_...
33
+ Open http://127.0.0.1:7340/
34
+ Boxes: none is ready, so sandbox agents do not run here. docker: not enabled on this server: start AgentRun with AGENTRUN_BOXES=docker.
35
+ Set your password: http://127.0.0.1:7340/setup (the first visit sets it)
36
+ ```
37
+
38
+ `Open` is [the console](#the-console), which takes [your password](#your-password). For a client, export the two lines before
39
+ it, then make an agent, start a run, and read its timeline until a page says `final`:
40
+
41
+ ```sh
42
+ H="authorization: Bearer $AGENTRUN_API_KEY"
43
+ curl -s "$AGENTRUN_BASE_URL/agents" -H "$H" -H 'content-type: application/json' \
44
+ -d '{"definition":{"id":"calc","name":"Calc","instructions":"Answer the question."}}'
45
+ run=$(curl -s "$AGENTRUN_BASE_URL/agents/calc/runs" -H "$H" -H 'content-type: application/json' \
46
+ -d '{"input":{"content":"What is six times seven?"}}' | node -p 'JSON.parse(require("fs").readFileSync(0)).run_id')
47
+ curl -s "$AGENTRUN_BASE_URL/runs/$run/timeline?wait_ms=5000" -H "$H"
48
+ curl -s "$AGENTRUN_BASE_URL/runs/$run" -H "$H"
49
+ curl -s "$AGENTRUN_BASE_URL/runs" -H "$H"
50
+ ```
51
+
52
+ An edit is a new revision: `PUT $AGENTRUN_BASE_URL/agents/calc/definition` with
53
+ `{"definition":{"instructions":"Answer in one word."}}` makes revision 2 current, and the next run runs it.
54
+
55
+ | Flag | Default | What |
56
+ | --- | --- | --- |
57
+ | `--data DIR` | `~/.local/share/agentrun/agents` | The agent store (`DIR/store.sqlite`) and its runs (`DIR/runs/<id>/`). The token is `DIR/.token`, mode 0600, made once and kept, unless `AGENTRUN_TOKEN` gives it. |
58
+ | `--listen ADDR` | `127.0.0.1` | The address to listen on. On any other, every `Host` name is served and the token is the only lock: put TLS in front of it. |
59
+ | `--port N` | the first free port from `7340` | The port. `0` is any free port. |
60
+ | `--open` | off | Open the console in this machine's browser once the server listens; not in CI, nor on Linux with no display. |
61
+ | `--faux MODULE` | none | Answer every model request from the module's default export (below). |
62
+ | `--allow-host NAME` | none | Another `Host` name to accept. Repeat it. |
63
+ | `--max-runs N` | `AGENTRUN_MAX_RUNS`, else as many pi runs as fit | The most runs at once, beside the memory each run's harness reserves ([capacity](#capacity-and-health)). Over either, a new run is `429 rate_limited`. |
64
+ | `--documents DIR` | `AGENTRUN_SERVE_DOCUMENTS` | A read-only directory of documents a workflow's `pdf_pages` calls read by file name, confined to it. |
65
+ | `--allow-code-nodes` | off (`AGENTRUN_SERVE_CODE_NODES=1` turns it on) | Run workflows' `code` nodes. They run in the run's process through the DSL's `new Function` transform, which is no sandbox, so only turn it on for workflows you wrote. Off, a workflow with a code node saves with a `not_set_up_here` warning and its runs are `409 agent_not_runnable` with `details.code: true`. A call `via: "shell"` or `"executor"` is refused either way. |
66
+ | `--learning on\|off` | on (`AGENTRUN_SERVE_LEARNING`) | Whether runs [learn](#learning). On, a run of an agent whose definition says `learning: true` starts from what that agent learned and adds to it; off, no run does, whatever its agent says. Any other value refuses the start. Capabilities report it as `features.learning`. |
67
+ | `--learning-budget BYTES` | `8000` (`AGENTRUN_SERVE_LEARNING_BUDGET`) | How much of what an agent learned its runs' instructions hold under `# Learned`, in UTF-8 bytes: every note whole while they fit, else the index and the notes changed last, whole, while they fit ([learning](#learning)). `0` gives the index alone. A value that is not a whole number of bytes refuses the start. |
68
+ | `--drain-timeout D` | `30s` (the image: `6s`) | How long a busy run may finish its turn when the server stops (`8s`, `500ms`, `1m`). A turn cut off resumes at the next start; its model request is sent again. The server keeps its data directory until its runs' processes have exited (up to this and a second), and says so as it stops; a server started on the same `--data` meanwhile waits for it, saying so, then starts. |
69
+
70
+ `AGENTRUN_TOKEN`, when set, is the token (32 characters or more), and the server prints `$AGENTRUN_TOKEN` in its
71
+ place: a token from the environment stays out of the logs. `DIR/.token`'s token is printed only by the start that made
72
+ it; a later start prints `AGENTRUN_API_KEY=<in DIR/.token>`, to read it there. With `AGENTRUN_ACCOUNTS=0` the `Open`
73
+ link carries the token (`?token=<in DIR/.token>` on a later start); it encodes the token, and the server also takes one
74
+ whose `+` arrived as a space. `AGENTRUN_PUBLIC_URL`, when set, is the
75
+ address people open (a container's published port, or a proxy's URL): the printed `Open` link and `AGENTRUN_BASE_URL`
76
+ use it.
77
+
78
+ ## Sandbox in 60 seconds
79
+
80
+ An agent with a shell, in a Docker container of its own: on a machine with Docker, in a checkout built as above, with
81
+ a model key. Start the server with the Docker box on:
82
+
83
+ ```sh
84
+ export AGENT_MODEL=openrouter/anthropic/claude-sonnet-5.5 OPENROUTER_API_KEY=...
85
+ AGENTRUN_BOXES=docker node packages/serve/dist/cli.js
86
+ ```
87
+
88
+ Its log says `event=boxes available=docker`, and its banner's last line `Boxes: docker is ready, so sandbox agents run
89
+ their tools there.` The first start builds [the box's image](#the-boxs-image) (python 3.12, git, curl, node and rg,
90
+ about 300 MB, a minute or two, the build alone on the network): its banner then says `Boxes: docker is preparing
91
+ (building the box image (python, git, curl, node, rg)).`, and the log `event=box_image ... state=preparing`, then
92
+ `state=ready` with how long it took; a later start finds it built. A run that needs its box sooner waits for it, with a
93
+ row on its timeline saying so. In a second shell, export the two `AGENTRUN_` lines it printed (a later start prints
94
+ where the key is: `export AGENTRUN_API_KEY=$(cat ~/.local/share/agentrun/agents/.token)`). Then make a sandbox agent,
95
+ run it, watch it, and read the file it wrote:
96
+
97
+ ```sh
98
+ H="authorization: Bearer $AGENTRUN_API_KEY"; J='content-type: application/json'
99
+ curl -s "$AGENTRUN_BASE_URL/agents" -H "$H" -H "$J" -d '{"definition":{"id":"boxed","name":"Boxed","instructions":"Do each step with bash.","place":{"mode":"sandbox","box":"docker"},"tools":["bash","write","read"]}}'
100
+ run=$(curl -s "$AGENTRUN_BASE_URL/agents/boxed/runs" -H "$H" -H "$J" -d '{"input":{"content":"Save what cat /etc/os-release prints in out.txt."}}' | node -p 'JSON.parse(require("fs").readFileSync(0)).run_id')
101
+ curl -sN "$AGENTRUN_BASE_URL/runs/$run/timeline" -H "$H" -H 'accept: text/event-stream' | grep -o '"summary":"[^"]*"'
102
+ curl -s "$AGENTRUN_BASE_URL/runs/$run/files" -H "$H"; curl -s "$AGENTRUN_BASE_URL/runs/$run/files/out.txt" -H "$H"
103
+ ```
104
+
105
+ The timeline ends when the run does. `out.txt` names the image's Debian, whatever this machine runs, and it is in
106
+ the run's `work/`, the one directory the container binds. No key? Start the server with `--faux box.mjs`, a
107
+ [faux model](#the-faux-model) that makes one `bash` call and then answers, and run the same commands:
108
+
109
+ ```sh
110
+ cat > box.mjs <<'JS'
111
+ export default (context, faux) => context.messages.some((m) => m.role === "toolResult") ? faux.message("Saved out.txt.")
112
+ : faux.message(faux.toolCall("bash", { command: "cat /etc/os-release | tee out.txt" }), { stopReason: "toolUse" });
113
+ JS
114
+ AGENTRUN_BOXES=docker node packages/serve/dist/cli.js --faux box.mjs
115
+ ```
116
+
117
+ The box has python 3.12, git, curl, node and rg, and no network: [the box's image](#the-boxs-image) says how to give it
118
+ more. The rest is under [Sandbox](#sandbox).
119
+
120
+ ## Logs
121
+
122
+ stdout gets one line per event, `at=<time> event=<name> key=value ...` (a value with a space is quoted):
123
+
124
+ ```
125
+ at=2026-10-25T21:04:05.120Z event=request method=POST path=/v2/agents/calc/runs status=202 ms=41
126
+ at=2026-10-25T21:04:05.121Z event=run_started run=01a1... agent=calc kind=agentic
127
+ at=2026-10-25T21:04:06.802Z event=run_ended run=01a1... agent=calc status=completed cost_usd=0.0012
128
+ at=2026-10-25T21:04:09.010Z event=auth_failed route=/v2/runs reason=wrong_token
129
+ ```
130
+
131
+ A request's path has no query. `auth_failed` names the route and why (`no_credential`, `wrong_token`,
132
+ `wrong_link_token`, `wrong_password`, `sign_in_table_full`), never the token given nor any part of it. `AGENTRUN_LOG=quiet` leaves out the request lines; the
133
+ run and `auth_failed` lines stay. A run whose process failed at its start says why in its `error.message`, in words.
134
+ One line at start, `event=boxes`, says which boxes this server has ([Boxes](#boxes)), and with a Docker box,
135
+ `event=box_image` says whether its image is `ready`, `preparing` (being built or pulled) or `unavailable` and why, again
136
+ when that ends; quiet keeps them too.
137
+ `event=harness_offers why=start ms=<n>` says how long the server took to check what each harness offers (each CLI's
138
+ package and pins; [harnesses](#harnesses)), the bulk of its start; quiet keeps it too. It is made at the start only: a
139
+ PUT of `/settings/tools` and a save or delete of a tool key change no harness's offer, so they remake capabilities at
140
+ once without checking again (a key some harness reads would, with `why=key`).
141
+
142
+ ## In a container
143
+
144
+ The image is public: `ghcr.io/parcha-ai/agentrun-server` (`:beta`, or an exact version such as `:v0.1.0-beta.27`).
145
+
146
+ 1. `docker run` it (below).
147
+ 2. Open the console and set your password.
148
+ 3. Sign in with it on any browser; the token in the log stays for scripts and the CLI.
149
+
150
+ On a fresh server with no `AGENTRUN_PUBLIC_URL`, whoever reaches the console first sets the password, so set it right after
151
+ `docker run`, before the port is reachable by anyone else. With `AGENTRUN_PUBLIC_URL` set, the setup code the server
152
+ prints still guards it.
153
+
154
+ With no checkout:
155
+
156
+ ```sh
157
+ export OPENROUTER_API_KEY=...
158
+ docker run -d --name agentrun -p 127.0.0.1:7340:7340 -v agentrun:/data \
159
+ -e AGENT_MODEL=openrouter/anthropic/claude-sonnet-5.5 -e OPENROUTER_API_KEY \
160
+ ghcr.io/parcha-ai/agentrun-server:beta
161
+ docker logs agentrun | grep Open
162
+ ```
163
+
164
+ On another port, publish it there and pass the address you open, so the printed link names it:
165
+ `-p 127.0.0.1:<port>:7340 -e AGENTRUN_PUBLIC_URL=<that address>`.
166
+
167
+ The image runs runner agents only: it cannot host a sandbox's boxes yet ([in the published image](#in-the-published-image)).
168
+
169
+ `packages/serve/docker/Dockerfile` builds that image: the server and the open packages it runs, on Node 22 and Debian 13
170
+ (trixie), with git 2.47 for `pi-git-remote`. Everything it keeps is under `/data`: the agent store, the runs and the
171
+ token. From a checkout, with compose:
172
+
173
+ ```sh
174
+ export AGENT_MODEL=openrouter/anthropic/claude-sonnet-5.5 OPENROUTER_API_KEY=...
175
+ docker compose -f packages/serve/docker/compose.yaml up --build -d
176
+ docker compose -f packages/serve/docker/compose.yaml logs agentrun
177
+ ```
178
+
179
+ The token is in the log of the start that made it. On a stop the server gives a busy run 6 s
180
+ (`--drain-timeout 6s`) to finish its turn, so a busy `docker stop` ends in about 7.5 s, inside Docker's default 10 s
181
+ grace, and Compose's `stop_grace_period` is 15 s; a turn cut off resumes at the next start. Compose publishes the port
182
+ on this machine's loopback only (`127.0.0.1:7340`, or `AGENTRUN_PORT`, which the printed link follows), and
183
+ the volume `agentrun-data` keeps `/data` across `down` and `up`. In the container the server listens on `0.0.0.0`, and
184
+ every route but `GET /v2/capabilities` and `GET /v2/health` still needs the token. Compose's `healthcheck` and
185
+ `render.yaml`'s `healthCheckPath` are `GET /v2/health`.
186
+
187
+ `render.yaml` at the repository's root is a Render blueprint for the same image: one web service with a 1 GB disk at
188
+ `/data`. Render generates `AGENTRUN_TOKEN`, which scripts and the CLI read in the service's Environment tab. With no
189
+ `AGENTRUN_PUBLIC_URL` the server takes Render's own `RENDER_EXTERNAL_URL` as its public address, so setup takes the
190
+ code the start prints in the service's log (`Set up this server: ...`). On another host, set `AGENTRUN_PUBLIC_URL` to
191
+ the address people open before the first start; without it, whoever opens the console first sets the password. Set
192
+ `AGENT_MODEL` and the provider's key there too. Render waits 30 s after SIGTERM, above the image's 6 s drain; it does not
193
+ let a service with a disk change that.
194
+
195
+ ## Upgrading from 0.1.0-beta.26
196
+
197
+ 0.1.0-beta.27 keeps every agent in one store, `DIR/store.sqlite`, with its revisions, and each run under `DIR/runs/<id>/`.
198
+ 0.1.0-beta.26 and earlier kept one agent home per agent, `DIR/<agent>/agent.sqlite`, and this version does not read
199
+ those. So it refuses to start on a data directory that holds one, and names each home it found, instead of serving
200
+ it as if it had no agents.
201
+
202
+ To keep those agents and their runs, keep the earlier version on that data directory. To start this version, give it a
203
+ new data directory (a new volume), or move the old homes out of the one you have. Then create the agents again, here or
204
+ through `POST /v2/agents`. Their earlier runs stay readable where you moved them, with the earlier version.
205
+
206
+ ## Capacity and health
207
+
208
+ Each run is a process of its own, and how much memory it takes depends on its harness. The server admits runs by
209
+ memory: each run that holds a live process (working, or waiting for an answer) reserves its harness's size out of the
210
+ container's limit when it has one (cgroup), else the machine's, less the server's own 128 MiB.
211
+
212
+ | Harness | Reserved per run | Measured per run |
213
+ | --- | --- | --- |
214
+ | pi | 128 MiB | up to 106 MB |
215
+ | codex | 192 MiB | up to 143 MB |
216
+ | claude-agent | 288 MiB | up to 215 MB |
217
+
218
+ The measure is a short task (write a file, read it back, answer) on a real server in a container of its own; the table
219
+ in `src/harness.ts` says how it was taken. So a 512 MB instance holds 3 pi runs, 2 codex runs or 1 claude-agent run at
220
+ once (or 1 codex and 1 pi), 1 GB holds 7, 4 or 3, and 8 GB 63, 42 or 28. A start that does not fit in what is left is
221
+ `429 rate_limited` with `retry-after`, its message naming the harness and the memory, and nothing starts: there is no
222
+ queue, so the client tries again once a run ends. A harness whose one run needs more than all the memory for runs (claude-agent
223
+ on a host under 416 MB) is unavailable: capabilities say why in its `harnesses` entry, and its runs are `409
224
+ agent_not_runnable` with that reason. pi always has one place, however small the host.
225
+
226
+ `--max-runs N` or `AGENTRUN_MAX_RUNS` caps the count as well (by default, as many as pi runs fit), and both limits
227
+ apply. Capabilities report pi's count in `limits.max_concurrent_runs`, and each harness's own in its `harnesses` entry
228
+ (`max_concurrent_runs`, beside `run_memory_mib`). A message to a run already going is never refused for a place, nor is
229
+ the relaunch of one whose process went, and a run's process the next server adopts after a restart holds its harness's
230
+ memory there. A run whose harness can never fit (the server restarted on a smaller host) is not started again: it fails
231
+ with why if it was working, and a message to it is `409 agent_not_runnable`.
232
+
233
+ A data directory serves one AgentRun Server at a time: two servers on a shared disk are not supported (each
234
+ counts only its own runs, and a run could be relaunched twice).
235
+
236
+ `GET /v2/health`, with no credential like capabilities, answers `200 {status: "ok", checks: {store: "ok", disk: "ok"}}`
237
+ when the agent store opens for a read and the data directory's disk has at least 64 MiB free (`AGENTRUN_MIN_FREE_MB`),
238
+ and `503` with `status: "failing"` and which check failed (`store: "does_not_open"`, `disk: "below_floor"`, or
239
+ `disk: "cannot_check"` when the free space cannot be read) otherwise.
240
+ It names no path, size or version. One route serves as both liveness and readiness: any answer says the server is up,
241
+ and a 200 says it can work, and the platforms here take one path.
242
+
243
+ A run whose end the agent store cannot take (a full disk) still ends: a cancel makes it `cancelled`, with its cost from
244
+ its rows, and the server writes the end to the store again every 30 s until it lands; a restart before then reads the
245
+ run as the store last had it. A run whose process was killed is opened again on its next message at once: a heartbeat
246
+ of a process that is gone is not trusted.
247
+
248
+ ## Sandbox
249
+
250
+ A sandbox agent's `bash` runs in a box, a machine apart from this server: today a Docker container made for each run,
251
+ which binds the run's `work/` and nothing else, or a Daytona sandbox, which gets a copy of it; either has no network and
252
+ no key. Its `read`, `write` and `edit` work on that same `work/`: on this server, where the box binds it and this server
253
+ holds directory handles (Docker on Linux), else in the box. The agent's loop, its log, its model calls and every key stay
254
+ on the server. An agent says so in its [place](#place); the server says which [boxes](#boxes) it has; [a run in a Docker
255
+ box](#a-run-in-a-docker-box) is what the container gets, and [a run in a Daytona box](#a-run-in-a-daytona-box) what a
256
+ Daytona sandbox gets;
257
+ [the box's image](#the-boxs-image) is what it starts from. [Sandbox in 60 seconds](#sandbox-in-60-seconds) is all of it
258
+ end to end. The [published image](#in-the-published-image) cannot host boxes yet.
259
+
260
+ ### Place
261
+
262
+ A definition may name where its runs execute: `{"mode": "runner"}` or `{"mode": "sandbox", "box": ...}`, the box one of
263
+ the ids under [Boxes](#boxes). A runner has no shell. In a sandbox the agent's `bash` runs in the named box and its
264
+ file tools (`read`, `write`, `edit`) work on the `work/` the box has ([a run in a Docker box](#a-run-in-a-docker-box)),
265
+ while the agent's loop, its log and every key stay on the server, whatever its harness. Any other shape is `422 input_invalid` on `definition.place`, whose `fix` is the change to make: the field to
266
+ remove, or the place it most likely meant, to copy (`"place": {"mode": "sandbox", "box": "docker"}`). A definition that
267
+ names none runs in this host's default (`capabilities.places.default`, `runner` here), and its answers show no place; one
268
+ that names a place keeps it, `runner` included. An edit that names no place keeps the agent's.
269
+
270
+ A run runs in its revision's place, else this host's default. A run request names no place: `POST /agents/{id}/runs`
271
+ with `place` is `422 input_invalid`, as with any field the body does not keep. The run keeps the place it resolved to,
272
+ and `GET /v2/runs/{id}` shows it as `place`. A harness's own tools in the box, when they come, will be an option of
273
+ `sandbox` (such as `native_tools: true`), never a third mode.
274
+
275
+ `bash` may be named only by an agentic definition whose place is a sandbox (`422` on a runner, named or by default, with
276
+ the sandbox place as its `fix`), and a workflow's place is `runner` or none (`422` on a sandbox, with the runner place as
277
+ its `fix`). In `capabilities.tools`, `bash` is `available: false` with a `reason` (`no box is set up on this server: …`,
278
+ each box's own reason) when no box this server has can run it.
279
+
280
+ `GET /v2/capabilities` lists `places`: the modes, the default, and each box with `available`, its `state` (`ready`,
281
+ `preparing` while the server builds or pulls its image, or `unavailable`) and, when it is not ready, the `reason`.
282
+ A definition naming a box this server does not have saves with a warning on `definition.place`, and a run of it is
283
+ `409 agent_not_runnable` with `details.box`. `GET /v2/openapi.json` marks `definition.place`, the run's `place` and
284
+ `capabilities.places` `x-agentrun-serve: "place/1"`.
285
+
286
+ ### A run in a Docker box
287
+
288
+ With `AGENTRUN_BOXES=docker` and a Docker daemon this server's user may use, a run whose place is
289
+ `{"mode": "sandbox", "box": "docker"}` gets one container, made on its first `bash` call (a run with none gets no
290
+ container). Those four tools are pi's own, on every harness. `bash` runs in the container. `read`, `write` and `edit`
291
+ run on this server, on the `work/` the container binds, because a `docker exec` costs half a second or more per call:
292
+ they follow no link anywhere on the way (one pointing inside `work/` included), take only a regular file with one hard
293
+ link, and write through a temporary file renamed over the old one, keeping its mode (a new file is `0644`). A refusal
294
+ says so and names the box's path; `bash`, in the container, can still reach the file. Where this server reaches
295
+ directories by path (no `/proc/self/fd`, as on macOS), or a box binds nothing, all four run in the container, made on
296
+ the first of them.
297
+ `web_fetch` (and `fetch_page`, its legacy name), `web_search` and the `monid.*` tools stay on this server, and so do
298
+ the run's loop, its log, its model calls and every key. What the server itself files in `work/` (monid's long answers,
299
+ the browser's evidence) never goes through a link a box's command planted there: each directory is held open on the
300
+ way (`/proc/self/fd`). On a host without it (macOS), where a link swapped in mid-walk could still turn a write, a sandbox run's `work/` gets none of
301
+ these files: monid's long answers say they could not be saved, and the browser's evidence is not filed. `browser` is runner-only for now (`422` in a sandbox place): its downloads
302
+ go through `work/` by path.
303
+
304
+ - The container binds the run's `work/` alone, read-write, at `/run/agentrun/run/work`, where the tools start. Nothing
305
+ else of the data directory enters it. `read`, `write` and `edit` take a path in that directory, relative or absolute,
306
+ or under the run's own `work/` on this machine, which names the same file there (another harness's cwd may name
307
+ one); any other (another path of this machine, `..` out of it, `~`) is refused as outside the workspace, and their
308
+ errors name the box's paths, never this machine's. A mount source that is, or passes through, a link below the data directory is
309
+ refused: the tool call fails, and no container is made. The data directory is resolved to its real path once, at start.
310
+ - It has no network (`--network none`); no setting opens it. Docker still binds its copies of this machine's
311
+ `/etc/resolv.conf`, `/etc/hostname` and `/etc/hosts` into it, read-only, so a box's command can read this machine's
312
+ resolver settings (its nameservers and search domains), with no network to use them. Its environment is
313
+ `LANG=C.UTF-8` and `HOME=/tmp` and the image's own: never this server's, so no key or token is in it. It runs as this
314
+ server's uid:gid, so what it writes in `work/` stays this server's. It starts from [the box's image](#the-boxs-image).
315
+ It may use 2 CPUs' time, 4 GiB of memory, swap included, and 1,024 processes and threads (`--cpu-period 100000
316
+ --cpu-quota 200000 --memory 4g --memory-swap 4g --pids-limit 1024`), so a runaway build or a fork bomb stops in the
317
+ box. `AGENTRUN_BOX_CPUS` (at least `0.01`), `AGENTRUN_BOX_MEMORY` (with its unit, such as `8g`, and at least `6m`) and
318
+ `AGENTRUN_BOX_PIDS` (at most 4,194,304) change them; any other value refuses the start. `AGENTRUN_BOX_CPUS` caps CPU
319
+ time, as a CFS quota (the cap `--cpus` sets), so it holds whatever CPU count Docker's VM has, and where the kernel
320
+ gives Docker no CPU controller (a rootless Docker without one delegated), Docker ignores it with a warning.
321
+ - `bash` takes pi's `{command, timeout?}`, `timeout` in seconds, 300 when the call names none; a timeout kills the
322
+ command's process group in the container. Its answer is its output's last 2,000 lines or 50 KB. Each call is a fresh
323
+ shell in `work/`.
324
+ - It has no capability and can gain none (`--cap-drop ALL`, `--security-opt no-new-privileges`), so even as root (a
325
+ server run as uid 0) it cannot make a device node in `work/`. Its Docker daemon must be this machine's: where
326
+ `DOCKER_HOST`, or the docker context, names another machine (tcp://, ssh://), no box is made, since that daemon would
327
+ bind its own paths, and the refusal says which setting to undo.
328
+ - The container is labelled `agentrun.run=<run id>`, and the label is its only record. A run's process that starts again
329
+ after a crash finds it by the label and first kills the commands the dead process left running. It is destroyed when
330
+ the run ends (completed, failed or cancelled: a follow-up after a completed run gets a fresh one, with the same
331
+ `work/`) and when the run is archived. A start destroys every such container whose run has ended or is archived; one
332
+ of a run this data directory does not know is left to its 24-hour lifetime.
333
+
334
+ ### A run in a Daytona box
335
+
336
+ With `AGENTRUN_BOXES=daytona` and `DAYTONA_API_KEY`, a run whose place is `{"mode": "sandbox", "box": "daytona"}` gets one
337
+ Daytona sandbox, made on its first `read`, `write`, `edit` or `bash` call, with the same tools, path rules, environment,
338
+ `bash` and labels as a Docker box. What differs (its `read`, `write` and `edit` run in the sandbox, as its `bash` does,
339
+ since nothing binds `work/` there):
340
+
341
+ - The key is this server's alone. The server makes, copies to and from, and destroys the sandbox itself. The run's
342
+ process holds no key: it reaches its sandbox only through the server's box relay, on loopback, which takes a call for
343
+ a run only with that run's own door token (`DIR/runs/<id>/door-token`, handed to that run's process alone) and adds
344
+ the key to the calls a run's tools make of their own sandbox (a read of it, and its toolbox's programs and files). It
345
+ refuses every other call (a create, a listing, a stop, a delete, another run's sandbox or token, any other host), and
346
+ it never follows a redirect, nor does the server's own Daytona client: a redirect would carry the key.
347
+ - Its network is blocked (`networkBlockAll`). A sandbox Daytona does not report blocked is deleted, and the tool call
348
+ fails saying so. An organization on Daytona's tier 1 or 2 keeps its own network policy, which a sandbox cannot
349
+ override, so a run there gets no Daytona box.
350
+ - A sandbox cannot bind `work/`. The server copies `work/` into it at `/run/agentrun/run/work` when it makes it, and
351
+ copies what changed back at each turn's end (a read of the run's files waits for that copy) and once more before the
352
+ run's end is recorded. Daytona's answer is never trusted: the copy back writes regular files and directories only,
353
+ never a link and nothing outside `work/`, and a file this server changed since the last copy stays as this server
354
+ has it. A file the box removed is removed here too. What the server files in `work/` during the run (monid's long
355
+ answers) is copied into the sandbox as well. The copy's mark is `box-sync.json` beside the run, which the server alone
356
+ writes; the run's process notes each file it copied in, in `box-mirrored.jsonl` beside it, and a copy back counts
357
+ those as held by both sides, so an edit the box makes to one comes back.
358
+ - The sandbox is destroyed after the last copy back, and only once that copy is whole: when the run ends, and when it
359
+ is archived (a copy that fails at an archive keeps the sandbox for the run's end). A copy that fails at the run's end
360
+ is tried again, and the end waits for it. One that stops for good (an archive the server cannot read, or a limit a copy
361
+ that brought nothing reached) keeps the sandbox, says so in the log (`event=box_kept` with its id), and lets the run
362
+ end with what did come back. A start pulls a run it finds waiting for the person, and copies back, then destroys, the
363
+ sandbox of every run that has ended or is archived. One whose copy fails is kept for the next start.
364
+ - A kept sandbox has Daytona's auto-delete turned off (a sandbox is made with auto-delete at 0, which deletes it as it
365
+ stops) and is set to stop after 15 minutes without activity, so once stopped it costs its disk alone (3 GiB on
366
+ Daytona's default snapshot, at Daytona's storage price) and no compute; its files stay. The next start wakes it, copies
367
+ back again, and destroys it once that copy is whole; else its 24-hour lifetime ends it. To remove one sooner, delete
368
+ the sandbox in Daytona's dashboard or API: it carries the labels `agentrun.box=run` and `agentrun.run=<run id>`.
369
+ - A run's sandbox that Daytona stopped, paused (a sandbox class that pauses when idle, while the run waits for its
370
+ person) or archived (a stopped one it moved away) is started again, an archived one restored, when the server next
371
+ needs it: for the run's next tool call, a copy back, or the start's sweep. One still stopping, pausing or archiving
372
+ is waited for (a minute at most) first. It is never replaced by a new one, so
373
+ what only it holds stays.
374
+ - The sandbox is Daytona's default snapshot, made as its user, with `sudo -n` making `/run/agentrun/run/work`.
375
+
376
+ ### The box's image
377
+
378
+ A Docker box starts from this server's own image by default: `agentrun-box`, python 3.12 (`python:3.12-slim`, pinned by
379
+ its digest) with git, curl, node (Debian's `nodejs`, no npm), rg (`ripgrep`) and their certificates, about 300 MB. Its
380
+ recipe is `BOX_RECIPE` in `src/box-image.ts`, its base `BOX_BASE` there. The server builds it on first use
381
+ (`docker build`, at most 10 minutes, its context a private directory under `TMPDIR` holding the recipe alone as its
382
+ `Dockerfile`, removed after), tags it with the recipe's hash (`agentrun-box:<12 hex>`) and labels it with the whole hash
383
+ (`agentrun.box-image`), and builds again only when the recipe changes: a start that finds the image with this recipe's
384
+ hash uses it. To move the base, read the tag's index digest again from Docker Hub (the comment beside `BOX_BASE` says
385
+ how) and put it there: the recipe's hash changes, and so does the image's tag, so the next start builds it. The build
386
+ reaches the network, for the base image and apt; a box made from it never does (`--network none`). A build that fails
387
+ leaves the box unavailable with the reason ([Boxes](#boxes)). Images of older recipes stay until you remove them:
388
+ `docker image ls --filter label=agentrun.box-image` lists them all, and `docker image rm agentrun-box:<12 hex>` removes
389
+ one.
390
+
391
+ A box has no network, so a run cannot install anything; the image has to bring it. For other tools, name another image
392
+ in `AGENTRUN_DOCKER_IMAGE`: the server then pulls it when Docker has none (at most 10 minutes) and builds nothing.
393
+ This image, its build and the wait for it are the Docker box's alone: a Daytona box is made by the server from
394
+ Daytona's own image, and a Daytona run never waits on this one.
395
+
396
+ ```sh
397
+ AGENTRUN_DOCKER_IMAGE=python:3.12-bookworm AGENTRUN_BOXES=docker node packages/serve/dist/cli.js
398
+ ```
399
+
400
+ `python:3.12-bookworm` adds compilers and the build tools of Debian's `buildpack-deps`. To bring your own, build one
401
+ `FROM` the base you want, tag it, and name the tag. An image based on Debian has what a box needs to run commands:
402
+ `sh`, `sleep` and `setsid`, and `bash` for the `bash` tool when there is one (else `sh`). The image's own entrypoint
403
+ never runs; the box's first process is a `sleep` of its lifetime.
404
+
405
+ ### In the published image
406
+
407
+ The published image, `ghcr.io/parcha-ai/agentrun-server`, cannot host boxes yet. It has no `docker` command and no
408
+ Docker daemon, so with `AGENTRUN_BOXES=docker` capabilities and the start's `event=boxes` line say docker is
409
+ unavailable, and a sandbox agent's runs are `409 agent_not_runnable`. Runner agents work as before. Do not mount the
410
+ host's Docker socket into the container to get around it: whatever can reach that socket is root on the host, and a
411
+ box's bind of `work/` names a path in the server's container, which the host's daemon does not have. For sandboxes, run
412
+ the server from a checkout on a machine with Docker ([Sandbox in 60 seconds](#sandbox-in-60-seconds)). A box that runs
413
+ inside the image itself (bwrap, on Linux) comes in a later release.
414
+
415
+ ### Boxes
416
+
417
+ A box is a machine apart from this one where a run's tools run. Runs execute in `docker` and `daytona` boxes
418
+ ([place](#place)); the others are set up and probed, and say runs in them are not available yet. `AGENTRUN_BOXES` lists the boxes to set up, as a comma list of the ids below
419
+ (`AGENTRUN_BOXES=docker,daytona`). The server never probes a box the list does not name, and a name that is no box
420
+ refuses the start. At start the server probes each listed box once. The probes run at once, each within 5 s. Then one
421
+ log line says what the server found:
422
+
423
+ event=boxes available=<ids or none> unavailable=<ids> <id>="<why>" ...
424
+
425
+ The line gives a reason for each listed box that is unavailable, and the banner says the same in words
426
+ (`Boxes: docker is ready, so sandbox agents run their tools there.`). Each reason says what to do next: a box the list
427
+ does not name says `not enabled on this server: start AgentRun with AGENTRUN_BOXES=docker` (keeping the boxes it already
428
+ lists), and a `docker` whose daemon does not answer says to start Docker or add this server's user to the `docker`
429
+ group, then restart the server, since the probe runs once. A reason never holds a key, a command's output or a
430
+ provider's answer.
431
+
432
+ - `docker`: the `docker` command on PATH, with a daemon that answers `docker version` for this server's user. It needs no key.
433
+ Then the server asks Docker for [the box's image](#the-boxs-image) (`docker image inspect`). When Docker has it (the
434
+ default with this recipe's hash), the box is `ready`. When not, the server builds the default, or pulls the image
435
+ `AGENTRUN_DOCKER_IMAGE` names, once, in the background, for at most 10 minutes. Meanwhile the box is available and
436
+ `preparing` (`building the box image (python, git, curl, node, rg)`, or `pulling <image>`), and a sandbox run whose
437
+ first box comes then waits for the image, with one row on its timeline (`Preparing the box image: building it (python,
438
+ git, curl, node, rg)…`), instead of a first tool call that pulls it silently. A build or pull that fails is tried once
439
+ more, 5 seconds later, the box `preparing` meanwhile with what failed (`trying once more: the build of the box image
440
+ could not reach the network (…)`). One that fails again, or takes longer, makes the box unavailable with the reason
441
+ (the build could not reach the network, pull its base or install a package, ran out of disk; the registry refused the
442
+ image, has no such image, could not be reached; or the time ran out) until a restart tries again. A run that was
443
+ waiting fails its call with that reason, and the next sandbox run is `409 agent_not_runnable`. A server stopped or
444
+ killed while its image comes leaves no run waiting on it: a run's first box fails its call at once, with `the server
445
+ stopped while building it: restart the server to build it again`, never Docker's own error, and the next start
446
+ builds it again.
447
+ - `daytona`: needs `DAYTONA_API_KEY`. Set `DAYTONA_API_URL` and `DAYTONA_TARGET` when Daytona's defaults do not fit.
448
+ The probe makes one authenticated read, of a box that does not exist. If Daytona refuses the key, the box is unavailable.
449
+ - `modal`: needs `MODAL_TOKEN_ID`, `MODAL_TOKEN_SECRET` and the SDK, which the host installs (`npm install modal`).
450
+ Its sandboxes live in the app that `AGENTRUN_BOX_APP` names (default `agentrun`). The probe checks that the SDK loads
451
+ and the token is set. It asks nothing of the provider.
452
+ - `bwrap` is not in this release yet.
453
+
454
+ The boxes come from `@parcha/pi-transport`, an optional peer of this package; install it beside the server to use any.
455
+ The keys belong to the server alone. The launcher hands them over with the server's other secrets, and no run's process
456
+ gets them, in its environment or on its pipe.
457
+
458
+ ## Models
459
+
460
+ An agentic revision names its model as `provider/model-id` (`"model"` in its definition), or names none and runs on
461
+ this host's default, `AGENT_MODEL`. With no `AGENT_MODEL`, a model provider's key, the server's own or saved as a
462
+ [tool key](#tool-keys), gives the default, the first of: `anthropic/claude-sonnet-5-5` with `ANTHROPIC_API_KEY`,
463
+ `openai/gpt-6.1-sol` with `OPENAI_API_KEY`, `openrouter/anthropic/claude-sonnet-5.5` with `OPENROUTER_API_KEY`. Each is
464
+ its provider's capable everyday model, not its dearest ($2 in and $10 out per million tokens); set `AGENT_MODEL` for
465
+ another. claude-agent takes only the Anthropic one and codex only the OpenAI one. A workflow revision names no model: each model node names a tier (`fast`, `default`
466
+ or `strong`), and the host maps it, `fast` to `AGENT_MODEL_FAST` and `strong` to `AGENT_MODEL_STRONG`, each falling back
467
+ to `AGENT_MODEL`. Capabilities show the mapping in `models` (`{source, route_prefix, fast, default, strong}`):
468
+ `source` is `gateway`, `providers` or `faux` (the published document marks these as `models/2`, beyond the contract's
469
+ `managed`, `chatgpt`, `env` and `faux`), and `route_prefix` is the routing prefix this server puts before a gateway's
470
+ model ids (`agent-model`), which a client takes off to show the gateway's own id, and null with any other source.
471
+ `models` also says `ready`, whether a revision that names no model runs here, and when it does not, `needs`: `key` (no
472
+ model provider's key, or none for the default's provider) or `model` (`AGENT_MODEL` names one this server does not
473
+ know). Where the models come from:
474
+
475
+ - `--faux MODULE`: every model is the module's (below), with no key and no network: `faux-1`, or for a tier the model
476
+ id its variable names.
477
+ - `AGENT_MODEL_BASE_URL`: every model id goes to that one OpenAI Responses endpoint, a gateway, at `<base>/v1/responses`
478
+ with one trailing `/v1` taken off the base first, as for every harness (OpenRouter's is `https://openrouter.ai/api` or
479
+ `https://openrouter.ai/api/v1`): a revision's `provider/model-id` is sent whole, as a gateway like OpenRouter names its
480
+ models `vendor/model`, and `AGENT_MODEL`, `AGENT_MODEL_FAST` and `AGENT_MODEL_STRONG` are sent as they are. For a
481
+ gateway that wants the id alone, `AGENT_MODEL_GATEWAY_IDS=bare` sends a revision's model without its provider. `AGENT_MODEL_API_KEY` is its key when it needs one. `AGENT_MODEL_PRICE` is `input,output,cacheRead[,cacheWrite]`
482
+ in USD per million tokens, so a run's cost estimate has a price; `AGENT_MODEL_FAST_PRICE` and `AGENT_MODEL_STRONG_PRICE`
483
+ price their tier's model, and default to it. With no price set, a model id pi-ai's catalog knows (`gpt-6-luna`, say)
484
+ takes the catalog's list price, and any other has no price: its answers' cost is unknown, so the run's `cost.usd` is
485
+ `null`, never $0. A model the catalog lists at $0, or one `AGENT_MODEL_PRICE=0,0` prices, is a known $0. A revision's `provider/model-id` takes that provider's
486
+ entry when it is paid; a bare id, a provider the catalog does not list for it, or one it lists at $0 takes the highest
487
+ price any provider lists (one entry's whole price, the most input plus output; a $0 entry never wins over a paid one),
488
+ as the gateway does not say whose model answers. A run's `max_cost_usd` therefore now stops a gateway run on such a model with
489
+ `spend_cap_reached`; at $0 it never did.
490
+ - Otherwise pi-ai's providers serve them, each with its key from the environment (`OPENAI_API_KEY`, `ANTHROPIC_API_KEY`,
491
+ `GEMINI_API_KEY`, `DEEPSEEK_API_KEY`, Bedrock's `AWS_*` keys, ...), and its catalog prices the run. The `AGENT_MODEL`
492
+ variables are then `provider/model-id` too. The launcher holds every key pi-ai reads, as it holds the rest, and a run's
493
+ process is handed a model key only when its model needs it: a pi run its model's provider's (a run on Gemini
494
+ `GEMINI_API_KEY`, one on `openrouter/...` `OPENROUTER_API_KEY`; a workflow each of its tiers'), or `AGENT_MODEL_API_KEY`
495
+ through the gateway; a codex run `OPENAI_API_KEY`, or `AGENT_MODEL_API_KEY` through the gateway; a claude-agent run
496
+ `ANTHROPIC_API_KEY`. No run gets another's. A workflow's decision nodes get their providers' keys on a descriptor of
497
+ their own, whatever its model, and only those ([Safety](#safety)).
498
+
499
+ A definition is checked for what keeps it from running here when it is saved, with the same checks a run makes before
500
+ it starts:
501
+
502
+ - What no setting of this host fixes refuses the save, `422 input_invalid` by field, and nothing is written: a tool
503
+ this host does not bind (`definition.tools[i]`), `bash` on an agent whose place is not a sandbox, a model pi-ai does
504
+ not know when no gateway is set (`definition.model`, saying why), empty instructions (`definition.instructions`), and a workflow that needs a tool
505
+ call this host does not run, code, or a node tool other than `read`, `write` and `edit` (`definition.workflow`, one
506
+ field per need).
507
+ - What a setting of this host fixes saves, and the `201` or `200` carries it in `warnings` (`[{field, reason:
508
+ "not_set_up_here", message}]`, empty when there is none): no key for the model's provider, no default model for a
509
+ revision that names none, no model for a tier a workflow's nodes name, no key for the decision provider a workflow's
510
+ typed questions name ([decision workflows](#decision-workflows)). A decision provider this server does not have
511
+ refuses the save.
512
+
513
+ A run is refused before it starts, `409 agent_not_runnable`, saying which, for any of these: a warning the host has not
514
+ fixed yet, or a revision saved before these checks. A run needs only the tiers it uses: an agentic one its model or the default, a workflow the tiers its nodes name, so a
515
+ workflow of fast nodes runs with `AGENT_MODEL_FAST` and no `AGENT_MODEL`. A run thinks at its `effort` (`low`, `medium`,
516
+ `high`), else at its agentic revision's `thinking` (`low` to `max`), else at the host's `AGENT_THINKING`, else at medium;
517
+ it is never off, and a model node that names its own thinking level keeps it. An agentic run started with an `effort` also
518
+ gets a short note on how to work, right after its instructions, on every harness (`src/effort-guidance.ts`): `low`
519
+ answers directly, `medium` plans briefly and checks once, `high` plans each part, fills the gaps and reviews. A run
520
+ started with none gets no note.
521
+
522
+ ## Tools
523
+
524
+ A revision names its tools from one closed table (`src/tools.ts`): each name is how the run's process binds it and the
525
+ variables of this server's environment it needs. Nothing outside the table can be named, and no tool is loaded from
526
+ anywhere else. `GET /capabilities` lists every one in `tools`, `available: true` or `false` with the variables it is
527
+ `missing` (their names, never their values), `nodes` for whether a workflow's model node may name it, and `calls` for
528
+ whether a workflow's `call` node `via: "tool"` may run it. A run of a
529
+ revision that names a tool outside the table, or one whose variables are not set, is refused before it starts (`409
530
+ agent_not_runnable`, with `details.unbound` and `details.missing`).
531
+
532
+ | Tool | What it does | Needs | A workflow's model node may name it, a call node run it |
533
+ | --- | --- | --- | --- |
534
+ | `read` | Read a file in the run's `work/` | nothing | yes, no |
535
+ | `write` | Write a file in the run's `work/` | nothing | yes, no |
536
+ | `edit` | Edit a file in the run's `work/` | nothing | yes, no |
537
+ | `bash` | Run a shell command in the run's box, from its `work/`: pi's `{command, timeout?}`, 300 s when the call names no timeout | an agentic definition whose place is a sandbox ([Sandbox](#sandbox)) | no, no |
538
+ | `ask_person` | Ask the person who started the run; the turn ends until a message answers | nothing | no, no |
539
+ | `web_fetch` | Read one web page from a public host through the guarded direct fetch, or through Parallel's extract where Parallel is picked ([search and fetch](#search-and-fetch)), a part at a time: `{url, offset?, max_chars?}` in, a Page out, `{ok, url, status, title, text, chars, truncated?, original_chars?, beyond_read?, offset?, next_offset?, html_chars?, converted?, links, links_omitted?, via, parallel?, refused?, error?}` | nothing (`PARALLEL_API_KEY` for Parallel, one billed extract a page a run) | yes, yes |
540
+ | `web_search` | Search the web, natively where the harness or the model's provider can, else through Parallel where the server holds its key, else keyless through Exa, or through the provider picked ([search and fetch](#search-and-fetch)): `{query, n?}` in, `{provider, query, results: [{url, title, snippet, published?}], text?}` or `{error}` out | nothing (`PARALLEL_API_KEY` for Parallel) | yes, yes |
541
+ | `browser` | A Browserbase browser on pi-browser's durable adapter: `snapshot`, `run`, `screenshot`, `browser_read`, `browser_release`, `browser_relaunch`, `browser_downloads` and `browser_upload` (into and from the run's `work/`) | `BROWSERBASE_API_KEY`, `BROWSERBASE_PROJECT_ID` | yes, no |
542
+ | `monid.discover` | Search monid's catalog of paid data endpoints in plain words: `{query, limit?, minScore?}` in, `{results: [{provider, endpoint, description, score, price}]}` out | `MONID_API_KEY` | no, no |
543
+ | `monid.inspect` | One monid endpoint before it runs: `{provider, endpoint}` in, the JSON Schemas of its input (`pathParams`, `queryParams`, `body`), its price, notes and documentation out | `MONID_API_KEY` | no, no |
544
+ | `monid.run` | Run one monid endpoint, paid per call from the monid wallet: `{provider, endpoint, input}` in, the run's `output`, `price` and `cost` out | `MONID_API_KEY` | no, no |
545
+ | `pdf_pages` | A workflow call only: `{path, maxPages?, dpi?}` in, `{name, pageCount, dpi, pages: [{page, image}], text}` out. Draws a document's first pages (3 by default, at 110 dpi) as PNGs under the run's `work/pages/<stem>/<dpi>/` (`<stem>`: the document's path below its directory made one name, with a short hash, so two documents of one file name never share pages), the dpi lowered so a page's long side is at most 1568 px, with its text (`pdftotext`, cut at 20,000 characters). A PNG or JPEG passes through as one page, scaled down to 1568 px. `path` is under `--documents` or the run's `work/`, never outside | `pdftoppm`, `pdftotext` | no, yes |
546
+ | `llm` | A workflow call only: `{prompt, system?, maxTokens?, tier?}` in, `{text, model, usage, cost_usd}` out. One completion on the run's model of the tier (`default`; a tier the state fills in, such as `"{requestedTier}"`, may be any of the three, and a tier with no model fails the call), no tools and no loop; `cost_usd` is null when the model has no price, never 0 | a model | no, yes |
547
+
548
+ `bash` runs only in a box: a runner agent, and a workflow, get no shell on this machine (see [Safety](#safety)). In a
549
+ sandbox place `read`, `write` and `edit` run in the box too. `fetch_page` is a legacy name for `web_fetch`: a
550
+ revision, a model node or a call node that names it still saves and runs, and gets `web_fetch` under that name (the
551
+ same Page with `via`, resolved as `web_fetch` is: the guarded fetch, Parallel only where picked). The table lists it no
552
+ more.
553
+
554
+ A call tool that fails on its own (an unreadable PDF, a model's refusal) fails its call node; inside a `map` with
555
+ `onItemFailure: "collect"` it fails that item, and the other items go on. A cancel or the node's deadline still
556
+ stops the run.
557
+
558
+ `web_fetch`'s direct fetch reaches public hosts only, through pi-browser's guard (`publicFetch`): each redirect hop is
559
+ resolved, every address it resolves to is checked, and the connection is dialled at the address checked, so a
560
+ loopback, private, link-local, carrier-grade or metadata address (`127.0.0.1`, `10.x`, `169.254.169.254`, `fc00::`,
561
+ `::ffff:127.0.0.1` and the like), a name such as `localhost`, a public name that resolves to one of them and a
562
+ redirect to one are all refused, as is any scheme but http(s). A URL on a port other than 80 or 443, or longer than
563
+ 4,096 characters, is refused before the guard is asked. A body is at most 5 MiB and a fetch at most 30 s. A Page holds
564
+ a part of the page's text: about `max_chars` characters from `offset` (20,000 by default, at least 200, at most
565
+ 50,000; a quote or a line break counts two, as the JSON answer holds it, and a part holds one character at least, so
566
+ it always advances), its length as `chars`. A part that is not the whole page says so: `truncated` while more follows,
567
+ `next_offset` where it begins, `original_chars` the page's whole length where it is known, and for an agent a line
568
+ after the JSON says which characters these are and the call that reads on. A page whose HTML is longer than 1,000,000
569
+ characters (scripts and styles aside) is cut before it is read: every part gives `html_chars`, the page's whole
570
+ length, and no `original_chars`, its text is the start of the page, and the last part's line says `The page was cut at
571
+ 1,000,000 characters of HTML before reading; the rest wasn't read.` `converted: "text"` says the text is the page's
572
+ plain text, its conversion to markdown having run out of time. A page is read to its first 1,000,000 characters: an
573
+ `offset` at or past them is refused, and the last part a read reaches of a longer page has `beyond_read`. The links,
574
+ absolute http(s) only, come with the part at offset 0: at most 200, in 20,000 characters, with `links_omitted`
575
+ counting those left out. A page is fetched once a run, at the first call for its URL, through either provider, and the
576
+ run keeps what it read of its last 8 pages by the URL asked for: every later part of that URL comes from it, with no
577
+ request, so a page's parts are always one read's. Through Parallel that is one billed extract a page a run, asked for
578
+ its first 1,000,001 characters (the extract has no offset: its text always starts at the page's start). A refusal or a
579
+ failure is a Page with `ok: false` and `refused` or `error`, never a thrown error: an agent reads why, and a workflow
580
+ can branch on it. An agent gets the Page as JSON text; a workflow's `call` node `via: "tool", tool: "web_fetch"` gets
581
+ it as its output (`args: {url, offset?, max_chars?}`, 50,000 characters of text by default, `out` a schema of that
582
+ shape). A call node naming a tool the table cannot run that way is refused before the run starts (`409`).
583
+
584
+ On another harness, every host tool's result reaches the model within the host's bound of 120,000 characters
585
+ (`HOST_RESULT_MAX_CHARS`, `@parcha/agentrun-kernel`): the kernel's tool bridge cuts a longer one, its start with a line
586
+ saying where it was cut, and flags the call `truncated`. Each CLI adapter tells its CLI to pass a result that long to
587
+ the model whole: the Claude Agent CLI would otherwise save a result past 50,000 characters to a file and tell the model
588
+ to read it, which a run's confinement refuses, and Codex keeps only the ends of a result past 10,000 tokens. A
589
+ `web_search` answer past 100,000 characters leaves out its least relevant results, `omitted` counting them.
590
+
591
+ ### Search and fetch
592
+
593
+ `web_search` and `web_fetch` work on every harness with only a model key. Each resolves, for a run, in one order: (1) the
594
+ provider the user picked, optional: the agent's own (`definition.tool_settings`) over the server's
595
+ (`PUT /settings/tools`); (2) the native tool, the harness's own or its model provider's hosted one (on claude-agent
596
+ only where it is picked: `auto` there skips Claude's own search, an explicit `native` pick); (3) for
597
+ `web_search`, Parallel, where the server holds a Parallel key (`PARALLEL_API_KEY` in its environment, or one saved on Tool
598
+ keys): `auto` then uses that key and bills it, each search booked as the run's cost ($0.001 a search); (4) the kernel's
599
+ keyless fallback. A revision's `tools` (and a pack's grant) names the capability, never a provider. On codex, `auto` is
600
+ Codex's own search, except behind a gateway, on OpenRouter (which runs neither Codex's nor Claude's own search, and
601
+ counts no searches to price) or under a spend cap (its request has no input bound, which a cap cannot
602
+ admit), where it is Parallel on the server's key, else keyless Exa. `off` turns `web_search` off: nothing is searched,
603
+ and an agent naming it is refused (`409`) until it is turned on again. A pick of `exa-keyless` is keyless Exa alone,
604
+ the key held or not.
605
+ A workflow's model nodes may each run on another tier's model, so a workflow's `web_search` never searches natively:
606
+ it is Parallel on the server's key, else keyless Exa, or the provider picked, and a pick of `native` alone is
607
+ unavailable for a workflow.
608
+
609
+ | | `claude-agent` | `codex` | pi |
610
+ | --- | --- | --- | --- |
611
+ | `web_search`, `auto` (the default) | Parallel on the server's key, else keyless Exa: Claude's own WebSearch is the `native` pick | Codex's own search, each search booked; behind a gateway, on OpenRouter or under a spend cap, Parallel on the server's key, else keyless Exa, a host tool | one request to the run's own model provider with its hosted search (Anthropic, OpenAI direct); behind a gateway (`AGENT_MODEL_BASE_URL`) or on another provider, Parallel on the server's key, else keyless Exa |
612
+ | `web_search`, `native` | Claude's own WebSearch, unavailable on OpenRouter or under a spend cap | the same, unavailable behind a gateway, on OpenRouter or under a spend cap | the same, unavailable where there is none: never keyless Exa |
613
+ | `web_search`, `off` | unavailable (`web_search is turned off in settings`): nothing is searched | the same | the same |
614
+ | `web_search`, `exa-keyless` | Exa's public MCP search, a host tool | the same | the same |
615
+ | `web_fetch`, `kernel` (the default) | the guarded direct fetch | the same | the same |
616
+ | either, `parallel` | Parallel's search and extract, host tools | the same | the same |
617
+
618
+ `GET /settings/tools` answers the server's settings, `{web_search: {provider}, web_fetch: {provider}}`, the default
619
+ where none is set; `PUT /settings/tools` takes the same map and replaces it (a capability it leaves out takes its
620
+ default). An agent's `definition.tool_settings` has the same shape and is over the server's. A provider is one offered
621
+ for its capability (`auto`, `native`, `exa-keyless` or `parallel` for `web_search`; `kernel` or `parallel` for `web_fetch`); an
622
+ unknown capability or provider is `422`, and so is a `permission` (`reason: not_yet`): permissions arrive with the tool
623
+ gate, and capabilities say `features.tool_permissions: false` until then. The settings are kept in the data directory
624
+ (`tool-settings.json`, 0600, written whole and durably), not a secret, and read by every run launched from then on.
625
+ `GET /capabilities` is the one tool catalog: each of the two tools there gives the providers offered (`providers`), the
626
+ server's (`provider`, its default where it sets none), the built-in default (`default_provider`) and `resolves`, what it
627
+ resolves to on each harness under the server's settings and default model (`native`, `kernel`, `exa-keyless`,
628
+ `parallel`, or `unavailable: <reason>`), with `why`, keyed the same, one plain sentence for each (`Codex's own search`,
629
+ `behind a gateway Codex has no own search; your Parallel key (saved)`, where `saved` is a key saved on Tool keys and
630
+ `server` one in the server's environment), both recomputed at each `PUT` and each key saved or deleted. `GET /agents/{id}` projects it onto the agent:
631
+ `tools`, each tool its current revision grants in the same order, and for one with a choice the provider in force,
632
+ `provider_from` (`agent`, its own `tool_settings`; `server`; or `default`), `default_provider` (the server's) and
633
+ `resolved`, on its harness and model. Parallel picked where
634
+ the server holds no `PARALLEL_API_KEY` resolves `unavailable: parallel picked, no PARALLEL_API_KEY`, never to another
635
+ provider: a revision naming the tool saves with a warning, and its run is `409` with `details.missing`.
636
+
637
+ The server resolves a run's tools at its first launch, from its pinned revision and the settings then, keeps the outcome
638
+ in the run's `serve.json` for the run's life (a later `PUT` changes the next runs, never a run already started; a
639
+ Parallel key gone since makes Parallel unavailable, never another provider), and hands its process the outcome as a
640
+ description with no secret in it (`AGENTRUN_SERVE_TOOL_PLANE`); the run reads its providers there, never from a request.
641
+ A workflow's tools are those its revision lists and those its model and call nodes name.
642
+
643
+ Upgrading: a server holding `PARALLEL_API_KEY` used to read every `web_fetch` page through Parallel's extract on its own.
644
+ Now `web_fetch` is the guarded direct fetch unless Parallel is picked; to keep the old behaviour, set
645
+ `PUT /v2/settings/tools {"web_fetch": {"provider": "parallel"}}` once (or `tool_settings` in an agent). Parallel's key reaches an agentic run only when one of its capabilities resolves to Parallel (see
646
+ [Decision workflows](#decision-workflows)), and a web tool reaches Parallel only where its own capability does.
647
+
648
+ pi's native `web_search` is one standalone request, as Claude's CLI runs its WebSearch: one user turn carrying the
649
+ query and an instruction to answer with sources, on the run's own model and key, with the provider's hosted tool added
650
+ and nothing else (Anthropic's `{"type": "web_search_20250305", "name": "web_search", "max_uses": 5}`, OpenAI's Responses
651
+ `{"type": "web_search"}`). The results, their citations and the search count are read from the provider's own events;
652
+ nothing of the request enters the run's conversation but the tool's answer, with `text`, the provider's own short
653
+ answer with its sources. A `pause_turn`
654
+ answers what it has, and nothing is retried. It is booked as one of the run's requests: its tokens at the model's price
655
+ plus $10 per 1,000 searches (Anthropic) or calls (OpenAI).
656
+
657
+ With no native search and no Parallel key, web_search falls back to Exa's public keyless MCP endpoint, a third-party
658
+ service with its own rate limits (unpublished) and its own terms (https://exa.ai/terms). To turn it off, set
659
+ `web_search` to `native` (native only) for the server (`PUT /v2/settings/tools`) or for an agent (`tool_settings`). To
660
+ search with a key instead, save a Parallel key on Tool keys (or set `PARALLEL_API_KEY`): `auto` then searches through
661
+ Parallel and bills the key.
662
+
663
+ Keyless Exa is one exchange with Exa's public MCP endpoint (`https://mcp.exa.ai/mcp`, its `web_search_exa` tool, at most
664
+ 8 results, no key), dialled over IPv4 alone: the server looks Exa's name up for IPv4 and connects to that address, since
665
+ Exa takes keyless use only over IPv4, straight to its endpoint (through a proxy it answers `403`, said by name). Past its
666
+ free limit Exa answers a `429` with a Retry-After, or a tool result it marks rate-limited (`ai.exa/rateLimited`); the
667
+ search is tried once more after a jittered 1 to 3 s, or the Retry-After Exa names when it is 5 s or less (a longer one, as
668
+ for its daily limit, is not waited out). Still limited, the tool answers `{error}` in our words: `Free web search is
669
+ rate-limited right now. Try again in a minute, or add a Parallel key in Settings → Tool keys to search with a key.` Any
670
+ other failure Exa answers reads `Free web search failed. Exa said: "<the first sentence of its text>"`, cut at 120
671
+ characters; Exa's own instructions (a key for its MCP URL) are never passed on.
672
+
673
+ Every provider answers one shape, `{provider, query, results: [{url, title, snippet, published?}], text?}`, `provider`
674
+ naming the one that served it (`native`, `exa-keyless`, `parallel`), each snippet cut at 3,000 characters; the answer
675
+ the model reads ends with one line asking it to cite the URL of each result it relies on.
676
+
677
+ `web_fetch` answers a Page with `via`, a part of the page at a time (`offset`, `max_chars`, as above). With Parallel
678
+ picked the page is read through Parallel's extract (`POST https://api.parallel.ai/v1/extract`, its full content as the
679
+ text, about $0.001 an extract, one a page a run) and `via` is
680
+ `"parallel"`, with status 200 and the absolute links of its markdown; when Parallel lists the URL in its errors, answers
681
+ with no content, a 5xx or not within 60 s, it is the guarded direct fetch, `via: "direct"`, with `parallel` saying why
682
+ Parallel gave no page (`refused the key (401)`, `answered 503`, `timed out`, `listed the URL in errors`, `not tried:
683
+ refused earlier in this run`), and the model reads a line saying so; a 401 or 403 stops Parallel for the rest of the
684
+ run. A fetch Parallel was not picked for says nothing of it. A URL passes the guard's own check before anything is sent to Parallel: a URL the guard
685
+ refuses is refused and never leaves the machine. A call stopped before its page arrived answers `ok: false` with
686
+ `via: "stopped"`: no page came for it (the run's read of the URL goes on for its other calls).
687
+
688
+ `web_search` through Parallel uses its Search API (`POST https://api.parallel.ai/v1/search`, its `fast` mode, about
689
+ $0.001 a search). On every provider the query is cut at 200 characters and `n` is 1 to 25 (10 by default). A result is a lead: the agent reads the page with `web_fetch`. A failure answers
690
+ `{error}`, with nothing searched instead; a 401 or 403 to either web tool stops Parallel for both for the rest of the run.
691
+
692
+ Parallel's fees are the run's spend, booked as monid's are: each search and each page Parallel extracts is marked in the
693
+ run's records before it is sent (`agentrun.tool_started`, held at its price) and settled once Parallel answers
694
+ (`agentrun.tool_cost`: `tool` `web_search` or `web_fetch`, `charged_by` `"parallel"`, `usd`), shown on its timeline
695
+ (`Tool cost: parallel charged $0.0010 for web_search`), summed into its cost and under `/usage`'s `tools` meter. Parallel
696
+ answers what it used as counts, never an amount, so each is booked at Parallel's published price (docs.parallel.ai,
697
+ read 2026-11-03), an estimate: a `fast` search $0.001 for up to 10 results and $0.001 for each one past them, an extract
698
+ $0.001 a URL; on a 4xx other than a 408 nothing (Parallel refused it), and on a 408, a 5xx, a timeout or a lost
699
+ connection its price (Parallel may have billed it). Under a [spend cap](#spend-cap) each is a paid call: sent only when
700
+ what the run has spent and holds, plus its price, fits the cap. Otherwise nothing reaches Parallel: a search answers the
701
+ cap's refusal (`spend_cap_reached: Parallel's search was not sent. It could cost up to $0.001 …`) and a page is the
702
+ guarded direct fetch, with `parallel` giving the same words. One sent holds its price until Parallel answers: a model
703
+ request checked meanwhile, from any branch, tool round or harness, counts it beside what the run has spent, so the two
704
+ never pass the cap together. A workflow's `call` node naming either tool is booked the same way, under the node's own
705
+ call (its execution path).
706
+
707
+ Keyless Exa, where `web_search` resolves to it, searches through Exa's public MCP endpoint (`https://mcp.exa.ai/mcp`, its
708
+ `web_search_exa` tool), with no key. What leaves the server is
709
+ the search query (cut at 200 characters) and the number of results asked for (1 to 8, 5 by default), nothing else
710
+ from the run, and no key. It goes to Exa over IPv4, straight from the run's process. Exa is a third party: its free,
711
+ keyless use has a rate limit it does not publish, and its own terms. Past that limit the search is tried once more, and
712
+ then is a tool error in our words (above): the model reads why and answers without it. A search ends at 60 s, its retry
713
+ included, so a call never hangs. The answer is the query and its results, each a URL, a title, a
714
+ snippet of at most 3,000 characters and its date when Exa knows it, then a line asking the model to cite the URLs it
715
+ relies on. Keyless Exa is the default for a harness with no native search when the server holds no Parallel key; `off`
716
+ turns `web_search` off, keyless Exa included.
717
+
718
+ The `browser` tool runs Browserbase sessions, never a Chrome on this machine. The keys come from the server's
719
+ environment and reach the run's process as the rest of it does. A session's custody (its lease, its tag, what it was
720
+ doing) is kept in the run's own store, so a run opened again on its directory reconciles the sessions it held. Each
721
+ page it reads is filed under the run's `work/evidence/`, each read in a file of its own (`0001-browser_read.md`, ...),
722
+ reads at once included. There is no recording and no live view. When the run is let go (its work done, or a SIGTERM)
723
+ the sessions it still holds are released at Browserbase.
724
+
725
+ `monid.discover`, `monid.inspect` and `monid.run` give an agent [monid](https://monid.ai)'s whole catalog of data
726
+ endpoints on one key, `MONID_API_KEY`: it finds an endpoint in plain words, reads its input schemas and price, and runs
727
+ it. Each run is paid per call from the monid workspace's wallet, and is sent once, never retried. An async provider's
728
+ run is read until it ends, about two minutes at most, and asked to stop at monid when the run stops or it outlasts that.
729
+ A refusal comes back as `{error, status?}` in words: the wallet too low (402), a workspace control such as its budget
730
+ (`BLOCKED`), `FAILED`, `TIMED_OUT`, the provider's own error (not charged). The model reads each answer as JSON cut at
731
+ 60,000 characters, the whole of it then filed under the run's `work/evidence/monid/`. An answer carries what monid
732
+ charged (`cost`, in dollars), and that charge is the run's spend: booked once in the run's own records as a tool cost
733
+ (`agentrun.tool_cost`: `tool` `monid.run`, `charged_by` `"monid"`, `usd`), shown in its timeline on a line of its own
734
+ (`Tool cost: monid charged $0.0030 for monid.run`) and summed into its cost, the total its [spend cap](#spend-cap)
735
+ reads, and `/usage` grouped by meter shows it as its own meter, `tools`, apart from `tokens`. Each run is marked in the
736
+ run's records before it is sent, held at the price an earlier `monid.inspect` of the run quoted for that endpoint, else
737
+ at an allowance of $1; its charge settles the mark. A mark a crash left unsettled leaves the run's cost unknown, as a
738
+ model request a crash cut does, and its cap counts it at its held figure, never $0. A run that may have charged and says
739
+ no cost (`FAILED`, `TIMED_OUT`, one stopped by the run or the wait, one whose sending failed) books an unknown charge,
740
+ never $0: the run's cost reads `null`, and under a cap it counts at its held figure, the bound the cap let it go at, as
741
+ a crash-cut mark does, so the run goes on while its cap allows, in its process and in one opened again from its store;
742
+ one monid says it did not charge (refused as sent, `BLOCKED`, `STOPPED`, the provider's error) books nothing. Under a
743
+ cap, each `monid.run` is held as a model request is: unless what the run has spent plus what the run is held at (the
744
+ price an inspect quoted, else the $1 allowance) fits its `max_cost_usd`, or when the spend is unknown, the call is
745
+ refused with a `spend_cap_reached` error the model reads, naming its price and the cap (and, when the allowance was
746
+ used, that `monid.inspect` gives a quote), and monid is never called. Runs go one at a time under a cap, and on
747
+ claude-agent and codex the check holds each model request still in flight at its worst case. A run sent holds its
748
+ figure until its charge is in, on every harness: a model request checked meanwhile counts it beside what the run has
749
+ spent, and a run that fails without an answer counts at it. `discover` and `inspect`
750
+ cost nothing and are never refused. They run on every harness: pi binds them, and claude-agent and codex call them as
751
+ host tools in the run's process, where a `monid.run` call a crash cut off is answered interrupted, never sent again
752
+ (`discover` and `inspect` may run again). On each, the model, the call's journal and the run's timeline name them
753
+ `monid_discover`, `monid_inspect` and `monid_run`: a model API takes no dot in a tool's name. The key is a secret like
754
+ the model keys: a run's process gets it over its pipe, never in its environment.
755
+
756
+ ## Tool keys
757
+
758
+ A tool's key comes from one of two places. The server's own environment, through its launcher: `PARALLEL_API_KEY`,
759
+ `MONID_API_KEY` and `BROWSERBASE_API_KEY` are among the secrets it hands the server over its pipe. Or the page, by name:
760
+ `PUT /v2/settings/tool-keys/{id}` with `{values: {NAME: "..."}}` saves one, field by field (`parallel` takes
761
+ `PARALLEL_API_KEY`, `monid` `MONID_API_KEY`, `browserbase` `BROWSERBASE_API_KEY` and `BROWSERBASE_PROJECT_ID`,
762
+ `typesafe` `TYPESAFE_API_KEY`, which unlocks Jev's decisions, `decisions.jev`), and `DELETE` forgets it. A model
763
+ provider's key is saved the same way (`anthropic`, `openai` and `openrouter`, each `kind: "model"`, the others
764
+ `"tool"`): every run gets it, as every run gets the launcher's model keys, and with no `AGENT_MODEL` it gives the
765
+ default model ([models](#models)); its `harnesses` are pi and the provider's own harness (OpenRouter's, all three), of
766
+ those this server runs or would run once the key is set, so a row names them before it is saved: one left out is one
767
+ this server cannot run for another reason (not installed, not the pinned build, more than this host's memory). `GET
768
+ /v2/settings/tool-keys` lists each key, what it unlocks and the harnesses that run that, and each field's `set` and
769
+ `source` (`server`, `stored` or null): never a value, nor any part of one. `unlocks` holds only what capabilities show
770
+ this server binds, its `tools` and `workflows.decisions.providers` (as `decisions.<id>`): a key whose tools it binds
771
+ none of still lists, with nothing in `unlocks`. A field the server is started with is the server's, and wins: saving
772
+ it is `409 key_set_by_server`. A value is text of at most 1024 bytes with no control character (`422` otherwise).
773
+
774
+ A key is checked against its provider before it is kept, with one call that costs nothing, given 5 s: monid's
775
+ discover of one result, Parallel's list of monitors, Browserbase's list of projects and TypeSafe's list of models (at
776
+ `BROWSERBASE_BASE_URL` or `TYPESAFE_BASE_URL` when the server is started with one). A key the provider refuses (401)
777
+ is `422 input_invalid`, its field's reason `refused_by_provider`, in plain words with the provider's first sentence
778
+ (`Monid refused this key (401: Invalid API key format)`) and never any of the key, and nothing is kept: a key saved
779
+ before stays as it was. Otherwise it is kept, and `GET` gives its row a `check`: `{state: "accepted", at}`, or
780
+ `{state: "not_checked", reason, at}` when the provider would not answer the check (403: a key scoped away from that
781
+ call may still work for its tools), did not answer in 5 s, could not be reached, answered a redirect (never followed,
782
+ so the key goes nowhere else) or something else, or has no call that costs nothing. `check` is null when the key is
783
+ not stored here (the server's own is not checked here); a key saved before this server checked keys reads
784
+ `not_checked`, and is checked when saved again. A save of Browserbase's project id alone sends no key, and leaves its
785
+ check as it was. A save whose check is still waiting when the server begins to close keeps nothing (`503
786
+ unavailable`, while its connection lasts): the check stops waiting, and the server's lock, released at close, may be
787
+ another server's by then. Under `--faux` a key is checked only against the fake its runs are given (`fauxMonid`,
788
+ `fauxParallel`, `fauxJev`); with none it is `not_checked`, and nothing reaches the network.
789
+
790
+ A saved key is kept only as ciphertext: AES-256-GCM in `DIR/tool-keys.json` (0600), each value bound to its field's
791
+ name, under the seal key `AGENTRUN_SEAL_KEY`, which only the server opens it with. A run's process never gets the seal
792
+ key. With `AGENTRUN_SEAL_KEY` not set, the launcher keeps it in `agentrun/seal.key` under `$XDG_CONFIG_HOME` (or
793
+ `~/.config`), making it the first time: 32 random bytes in base64, 0600 in a 0700 directory, and one another user can
794
+ read is refused, not changed. It is outside the data directory on purpose: a copy or a backup of the data directory
795
+ holds the keys as ciphertext alone, and opens nowhere without the seal key. With no seal key (started with no launcher and
796
+ no `AGENTRUN_SEAL_KEY`, or with no home directory) nothing is saved, never in the clear: `409 no_sealing_key`, and capabilities' `features.tool_keys.at_rest` is
797
+ `unavailable` (`sealed` otherwise).
798
+
799
+ A stored value that does not open is never a reason not to start. It reads `set: false, stored_unreadable: true`, and
800
+ `reenter` names those fields with why: `seal_key_missing`, `seal_key_changed` (a lost `seal.key` is made anew, so it
801
+ shows as this) or `file_unreadable`. The log says so once, naming the condition and the file, never a value; a `PUT` of
802
+ the value seals it again under the current key. In a container, `~/.config` is the container's own and goes with it:
803
+ pass `AGENTRUN_SEAL_KEY`, or mount a directory at `XDG_CONFIG_HOME`, so a new container opens the keys the volume holds.
804
+
805
+ A saved key is read by name like one the launcher hands over, and the launcher's value wins for a name it holds. A run
806
+ gets the saved keys at its launch, over the pipe its secrets come on (a workflow run's `PARALLEL_API_KEY` on its
807
+ decision descriptor), never in any process's environment, and never the seal key. No restart: a `PUT` or `DELETE`
808
+ answers once capabilities, a save's checks and a run's checks see the change, in milliseconds. No harness reads a tool
809
+ key, so a key leaves what each harness offers as it is, and the harnesses are not checked again. A run already
810
+ running keeps what it was handed; the next run started, or a run's process started again, takes what is saved then.
811
+ `BROWSERBASE_PROJECT_ID` is on the launcher's list for this, as every field a person may save is. Capabilities name each
812
+ tool's key (`tools[].key`, a `GET /settings/tool-keys` id, `browserbase` for `browser`), so a page can link a tool's
813
+ missing names to where its key is saved. `agentrun-serve import` opens the saved keys in its data directory too and
814
+ cuts each out of what it writes, as it cuts a key-shaped variable of its environment; one that does not open there is
815
+ not known, so not cut, and the import says so.
816
+
817
+ ## MCP servers
818
+
819
+ Add a remote MCP server once, with its credential, and see its tools before you keep it. Agents granting its tools
820
+ come in a later version; this is the API that saves the server.
821
+
822
+ ```sh
823
+ curl -X POST "$BASE/v2/settings/mcp-servers/preview" -H "authorization: Bearer $TOKEN" -H 'content-type: application/json' \
824
+ -d '{"url": "https://mcp.example.com/mcp", "auth": {"type": "bearer", "token": "..."}}'
825
+ curl -X PUT "$BASE/v2/settings/mcp-servers/example" -H "authorization: Bearer $TOKEN" -H 'content-type: application/json' \
826
+ -d '{"url": "https://mcp.example.com/mcp", "auth": {"type": "bearer", "token": "..."}}'
827
+ ```
828
+
829
+ `POST /v2/settings/mcp-servers/preview` takes `{url, auth}` (or `{name}` for a saved server) and connects over
830
+ Streamable HTTP with the official MCP SDK client (`@modelcontextprotocol/client`): the 2026-07-28 revision first, a
831
+ 2025-era server through its `initialize`. It answers the revision agreed (`protocol`), the server's `server_info`, any
832
+ `instructions` and every tool `tools/list` gives, all pages, each with its name, title, description, `input_schema`,
833
+ `output_schema` and `annotations` (the server's own claims, not checked). It stores nothing. `auth` is `{type: "none"}`
834
+ (or absent), `{type: "bearer", token}` (sent as `Authorization: Bearer <token>`) or `{type: "headers", headers: {Name:
835
+ value}}` (up to 8). `oauth` is refused for now (`422`, reason `not_yet`). `url` is `https`, or `http` on loopback.
836
+
837
+ What can go wrong, told apart:
838
+
839
+ - `422 auth_required`: the server answered 401 or 403. `details.auth` is `oauth` when it names protected-resource
840
+ metadata (in its `WWW-Authenticate`, or at `/.well-known/oauth-protected-resource`), else `bearer`.
841
+ - `422 not_mcp`: the URL answered, but nothing it answered was a JSON-RPC reply (a web page, a JSON API, a 404).
842
+ - `422 input_invalid`, field `url`, reason `redirect`: the server answered a redirect. None is followed, so a
843
+ credential goes only to the address you gave; the message names where it points.
844
+ - `424 upstream_failed`: the server could not be reached, did not answer within 15 s (30 s for the whole listing),
845
+ answered 5xx or more than 4 MiB at once, or failed to list its tools; `details.status` is its HTTP status, if any.
846
+
847
+ A server is kept with at most 500 tools and 1 MiB of tool names, descriptions and schemas: past either, the listing
848
+ stops at that page and the answer is `422 input_invalid` (field `url`, reason `too_many_tools` or `tools_too_large`),
849
+ naming the limit and how many tools were read.
850
+
851
+ `PUT /v2/settings/mcp-servers/{name}` previews the same way, then keeps the server: its URL, the tools it listed (the
852
+ snapshot an agent will be shown) and its credential. A name is lowercase letters, digits and dashes, starting with a
853
+ letter, at most 32, with no underscores, so `mcp__<server>__<tool>` splits one way. Each credential header's value is
854
+ sealed like a [tool key](#tool-keys): AES-256-GCM under `AGENTRUN_SEAL_KEY`, bound to the server's name and the header,
855
+ in `DIR/mcp-servers.json` (0600, written whole, synced and renamed), which holds no value in the clear. With no seal key,
856
+ a server that takes a credential is `409 no_sealing_key`, before anything is contacted; one with `auth.type` none is
857
+ kept. A `PUT` that sends no `token` (or no `headers`) keeps the sealed credential, as long as the auth type and the URL's
858
+ origin stay the same: a saved credential never goes to another origin unless you send it again.
859
+
860
+ `GET /v2/settings/mcp-servers` and `GET .../{name}` show each server with `credential`: `sealed`, `seal_key_missing`
861
+ (no seal key now) or `unreadable` (sealed under another key, or damaged: a `PUT` with the credential seals it again),
862
+ null for `auth.type` none. No read, log line or error shows a credential; a server's error text is cut of the values
863
+ sent before it is shown. `POST .../{name}/refresh` lists the tools again with the saved URL and credential, keeps them,
864
+ and answers `{added, removed, changed, server}`: `changed` names a tool whose title, description, schemas or
865
+ annotations differ. `DELETE .../{name}` forgets the server and its credential. A saved-servers file that does not read (damaged, or
866
+ another format) is never written over: the list answers `servers: []` with `file_unreadable: true`, and every other
867
+ route is `409 store_unreadable` until the file is restored or removed. Capabilities' `features.mcp_client`
868
+ says `transports: ["streamable-http"]`, the `auth` types and `at_rest` (`sealed`, or `unavailable` with no seal key).
869
+
870
+ `test/fixtures/fake-mcp-server.mjs` is a loopback MCP server for trying this: `startFakeMcp({era, token, oauth})`
871
+ answers `{url, log, tools, close}`; it serves `add`, `slow_write`, `delete_thing` and `paid`, and logs each request's
872
+ method, tool and whether an `Authorization` header came, never its value.
873
+
874
+ ## Webhooks
875
+
876
+ One URL hears of your runs without anyone watching the page. `PUT /v2/settings/webhook` with `{url}` sets it: an `http`
877
+ or `https` address, with no user or password in it. Loopback and private-network addresses are allowed, so a receiver
878
+ on your own machine or network works. Two kinds of message are POSTed to it: `run.needs_input` when a run comes to
879
+ need its person (`input_required`: an `ask_person` question, or a stopped turn) and `run.ended` when it ends
880
+ (completed, failed or cancelled, once carried back).
881
+
882
+ A run's end and its `run.ended` are one durable step. The server chooses the end's time once and gives it to the agent
883
+ store, so the row's `ended_at` and the message's `webhook-id` name one time. `run.ended` is queued only once the agent
884
+ store has the end, so a receiver that reads the run back on its message (`GET /v2/runs/{id}`) reads it ended; while the
885
+ store refuses the end (a full disk, a busy store), nothing is sent, until a later try of the write or the next server
886
+ stores it. The outbox (`DIR/webhook-outbox.json`) keeps, in the same write as each message, which end and which wait of
887
+ each run it queued. A server that starts queues any end of the last day that the agent store holds and the outbox does
888
+ not, under the same `webhook-id` (one lost to a kill, or to a crash of the machine; one whose run's `serve.json` can't
889
+ be read goes with an empty `title`), and a server that takes over a run
890
+ queues a wait it stands at that the outbox does not name (one the run came to while no server was up), under its one
891
+ `webhook-id`. The first start of a server that keeps this writes when it began (`DIR/end-notices-since`); an end before
892
+ that time (an older server's) or before the webhook was set is never sent. A run is continued only once its end's
893
+ `run.ended` is in the outbox on disk (`503` meanwhile), so a continued run's next end is its own, under its own id.
894
+
895
+ ```json
896
+ { "type": "run.needs_input", "timestamp": "2026-11-01T12:00:00.000Z",
897
+ "data": { "run_id": "…", "agent_id": "triage", "status": "input_required", "title": "…",
898
+ "url": "https://agents.example.com/#/runs/…", "pending": { "kind": "question" } } }
899
+ ```
900
+
901
+ A message is thin: ids, the status, the title and a link to the run on the page; never a tool's arguments, an output
902
+ or an input, which the API reads (`GET /v2/runs/{id}`). `pending.kind` is `question` (an `ask_person`) or `stopped`.
903
+
904
+ Messages are signed by the [Standard Webhooks](https://www.standardwebhooks.com) spec, so a receiver verifies them
905
+ with any of its libraries: `webhook-id` (the same on every try of a message, so it is the receiver's idempotency key),
906
+ `webhook-timestamp` (Unix seconds) and `webhook-signature: v1,<base64 HMAC-SHA256 of "{id}.{timestamp}.{body}">` under
907
+ the secret's bytes. A receiver checks the signature against the raw body and refuses a timestamp more than 5 minutes
908
+ from its clock, so a replay does not pass. The first `PUT` makes the secret, `whsec_` and 32 random bytes in base64,
909
+ and answers `201` with it, once; `GET /v2/settings/webhook` never shows it. It is kept like a [tool key](#tool-keys):
910
+ sealed under `AGENTRUN_SEAL_KEY` in `DIR/webhook.json` (0600), so with no seal key no webhook is set
911
+ (`409 no_sealing_key`). A new secret is a `DELETE` and a `PUT`.
912
+
913
+ A try that is not answered 2xx within 15 s fails; a redirect is not followed. A failed message is tried again on the
914
+ spec's schedule, with jitter: after about 5 s, 5 min, 30 min, 2 h, 5 h and 10 h, then logged as failed
915
+ (`event=webhook condition=delivery_failed`). Each message goes on its own tries, so two queued close together can
916
+ arrive in either order: a receiver orders them by `webhook-timestamp`, or reads the run (`GET /v2/runs/{id}`). A
917
+ `410 Gone` turns the webhook off (`disabled` in `GET`, and the log says why) until a `PUT` sets it again. Pending messages are kept in `DIR/webhook-outbox.json`, so the next server goes on with
918
+ them after a restart; a message can then come twice, under the same `webhook-id`. `GET /v2/settings/webhook/deliveries`
919
+ lists the last 50 attempts (`webhook_id`, type, status code, latency, error, when, and the next try's time), and
920
+ `POST /v2/settings/webhook/deliveries/{webhook_id}/redeliver` sends one of those messages again, once, under the same
921
+ `webhook-id`. `POST /v2/settings/webhook/test` sends a `webhook.test` message once and answers how it went. A webhook a
922
+ 410 turned off sends nothing, a test or a redelivery included (`409 webhook_off`), until a `PUT` sets it again.
923
+ `DELETE /v2/settings/webhook` removes the webhook and drops its pending messages.
924
+
925
+ ## What it serves
926
+
927
+ | Route | Here |
928
+ | --- | --- |
929
+ | `GET /health` | Without a credential: whether the store reads and the disk has room ([capacity and health](#capacity-and-health)). |
930
+ | `GET /openapi.json` | Without a credential: this API as an OpenAPI 3.1 document, the `agentrun.v2/0` contract (vendored in `src/openapi/`, its source in `info`) with this server's own routes marked `x-agentrun-serve` the operations it answers `501` marked `x-agentrun-serve-unsupported`, and a contract operation that takes more than the contract gives marked `x-agentrun-serve-changed` with each change named; `links.openapi` in capabilities points at it. |
931
+ | `GET /capabilities` | Without a credential. `backend: local`, every feature flag present and true only when it works; `tools`, the tools an agentic revision may name; `workflows`, what a workflow revision's model nodes get and, in `workflows.decisions.providers`, the decision providers its typed questions run on; `models`, where models come from and the model of each tier. |
932
+ | `POST /agents`, `GET /agents`, `GET /agents/{id}` | `POST` takes `{definition, skills?, note?}` and makes the agent with its first revision, current. A definition has `instructions` (an agentic revision) or `workflow` (a workflow revision, checked by the DSL first), and `name`, `description`, `model` and `thinking` (agentic only), `harness` ([harnesses](#harnesses)), `place` ([place](#place)), `tools`, `tool_settings` ([search and fetch](#search-and-fetch)), `skills` (names; each `<name>/SKILL.md` is in `skills`) and `version`, which is the number the revision gets. A field the store does not keep (`input_schema`, `output_schema`, `max_cost_usd`) is `422 input_invalid` by name, and so is a definition that can never run here; one this host cannot run yet saves with `warnings` ([models](#models)). The ETag (`home_etag`) is the current revision's id. `GET /agents/{id}` adds `tools`, the tools its current revision grants with each one's provider ([search and fetch](#search-and-fetch)). |
933
+ | `PUT /agents/{id}/definition` | The same body, checked [the same way](#models): a new revision, its parent the current one, made current. Without `skills` the current revision's skill files carry over. A definition that is the current revision already writes nothing, so a PUT sent twice makes one revision. An agent's id, name and description stay those it was made with. `If-Match` that is not the current ETag is `412 precondition_failed`; the store compares it again inside the commit, so of two edits that read the same revision exactly one lands. The contract's body is taken too: the definition itself, with `If-Match` required (`412` without it) and `definition.version` greater than the current one (`422`). Any such version is taken, and always makes a new revision, the same definition included; the revision is numbered as this server numbers them, the next, and the answer says which; the route reads a body holding `definition` as this one, any other as the contract's. |
934
+ | `GET /agents/{id}/revisions` | The agent's revisions, newest first: `revision`, `version`, `parent`, `kind`, `current`, `note`, `created_at` and the `definition`. |
935
+ | `POST /agents/{id}/current` | `{revision}`: one of the agent's revisions becomes current again. |
936
+ | `POST /agents/{id}/archive`, `POST /agents/{id}/unarchive` | [Archiving](#archiving): hides the agent and its runs from the lists, or shows them again. Answers the agent, with `archived_at`. |
937
+ | `POST /agents/{id}/runs`, `GET /agents/{id}/runs` | A run of the current revision, or of `revision`. An agentic run's input is `{content: string}`; a workflow run's is what its workflow's input schema takes. `file_ids` names [uploaded](#uploads) files, copied into the run's `work/inputs/` before it starts and named in its first message. The agent's runs, newest first. |
938
+ | `GET /runs` | Every agent's runs, newest first, a page of at most 100; `agent`, `revision` and `status` narrow it, and `archived=true` lists only archived ones. A failed run's summary carries its `error`, and a waiting run's its `pending`. |
939
+ | `GET /runs/{id}` | The run: its revision, kind, status, state, result, error, `pending` (this server's own, `pending/1`: what it waits on, by `kind`, such as `{kind: "question", question, asked_at}` for a question it asked a person; else null) and cost (`basis: estimate`; $0 before its first model request, a cancelled run's included). |
940
+ | `GET /runs/{id}/timeline` | JSON pages with the change-number cursor (`after`, `next_after`, `reset`, `drop`, `has_more`, `final`, `wait_ms` long poll, and this server's own `limit`, 1 to 500 rows a page, default 500), or server-sent events with `Accept: text/event-stream` (`id` is the cursor, `Last-Event-ID` resumes). Rows sort by `seq`; the usage row (`Cost so far`), the run's running total, is always the last row, and moves to the end when a row comes after it. |
941
+ | `POST /runs/{id}/messages` | To an agentic run: `steer` while the agent works, `answer` when it asked the person, `follow_up` after a stop or after it completed: a completed run opens again, the same run on its own session and store, takes a place under `--max-runs` (`429` when none is free), and completes again. A failed or cancelled run, an archived run and a run of an archived agent are `409 not_continuable`; a workflow run takes none (`501`). |
942
+ | `POST /runs/{id}/stop`, `POST /runs/{id}/cancel` | Stop ends an agentic run's turn and leaves the run `input_required` and idle. Cancel ends a run `cancelled` once its process has exited. |
943
+ | `POST /runs/{id}/archive`, `POST /runs/{id}/unarchive` | [Archiving](#archiving) one run. Answers the run, with `archived_at`. |
944
+ | `GET /runs/{id}/files`, `GET /runs/{id}/files/{path}` | The files under the run's `work/`, raw. |
945
+ | `POST /files`, `PUT /files/{id}`, `GET /files`, `GET` and `DELETE /files/{id}` | [Uploads](#uploads): a file sent in one call (`POST /v2/files?path=...`, its bytes the body), or reserved and then sent (`PUT /v2/files/{id}`); the server's uploads listed, read and deleted. |
946
+ | `GET /agents/{id}/home/files`, and `GET`, `PUT`, `DELETE` on a file's path below it | The files in the agent's home, listed, read, written and deleted ([agent home](#agent-home)). This server's own routes (`x-agentrun-serve: "home/1"`). |
947
+ | `GET /stats` | This server's own route, outside the contract (`x-agentrun-serve: "stats/1"`): the agents, the runs (`total`, `active`, `needs_input`, `failed`, `needs_review`, `status_unknown`), each agent's run count, the cost and what is archived, read from the agent store's aggregates alone, no run's files opened. Archived agents and runs are left out of every number but `archived`. A completed or cancelled run counts only in `runs.total`, but for an escalated one (completed, waiting for a person's review), which `needs_review` (`stats/3`) counts; `failed` never does. Each running run is in exactly one of `active` (queued or working) and `needs_input` (`input_required`), both from the runs this server holds, and `status_unknown`: a running run it does not hold, or holds as ended before its end is written. `cost.usd` sums the runs that ended with a cost and is null when none did, never $0, with `basis` `estimate`, or null beside a null `usd`; `unknown_runs` counts the rest. `analytics` (`stats/2`) sums the runs' metrics over the runs not archived that `from` and `to` (RFC 3339 date-times to the millisecond, an impossible one or a finer fraction refused; runs started in [`from`, `to`)) and `agent` pick, each optional, 400 when malformed: `filter` echoes them; `totals` (runs, completed, an escalated run included, `needs_review` (`stats/3`), failed, never an escalated run, `runs_with_metrics`, tokens and each token kind, requests, unmetered, `cost_usd` and `unknown_cost_runs`), `time` (`wall_ms` over the ended runs, `active_ms` where metrics have it), `by_harness_effort`, `by_day` (UTC), `by_source` (`live` or the import source) and the top 20 `tools`. A run with no metrics counts in `runs` and in no token sum. `learning` (`learning/1`) counts the runs that tried to learn over the same filters, from the learning ledger and the runs this server holds ([Learning](#learning)). The query bounds `analytics` and `learning` alone. |
948
+ | `GET /runs/{id}/graph` | A workflow run drawn, live: its workflow, the DSL's `workflowGraph`, each node's state (a map's items with their labels and the branch each route took for them, a route's branch), every decision with its receipt (answers, evidence, the state the judge saw, image links), every call with its input and output, and the totals (cost, null when any part is unknown). While the run goes it reads the run process's `live.json`, rewritten every 300 ms, never the run's store, which the process holds; a poll never answers `home_busy` (`stale: true` marks a last whole view). An agentic run has none (`404`). |
949
+ | `POST /runs/{id}/pause`, `POST /runs/{id}/resume` | A workflow run: what is in flight finishes, and no node, model call or decision starts until it is resumed. Its status reads `paused`, and stays so across a server restart. An agentic run is `501`, an ended one `409`. |
950
+ | `POST /workflows/validate` | `{workflow, tools?}`: every issue a save would refuse (`[{path, code, message}]`, the DSL's validation with code not run) and what this host lacks as `warnings`. Writes nothing. A refused save's `422` carries each issue as a field under `definition.workflow`, with its `code`. |
951
+ | `GET /settings/tool-keys`, `PUT` and `DELETE /settings/tool-keys/{id}` | [Tool keys](#tool-keys), this server's own routes (`x-agentrun-serve: "toolkeys/1"`): each key's fields by name and where each is set, never a value; save one sealed, or forget it. |
952
+ | `GET /settings/mcp-servers`, `POST /settings/mcp-servers/preview`, `GET`, `PUT` and `DELETE /settings/mcp-servers/{name}`, `POST .../{name}/refresh` | [MCP servers](#mcp-servers), this server's own routes (`x-agentrun-serve: "mcpservers/1"`): preview a remote MCP server's tools, save it with its credential sealed, read it back without the credential, refresh its tools, or forget it. |
953
+ | `GET /settings/tools`, `PUT /settings/tools` | This server's own: the providers of `web_search` and `web_fetch` ([search and fetch](#search-and-fetch)). |
954
+ | `GET`, `PUT` and `DELETE /settings/webhook`, `POST /settings/webhook/test`, `GET /settings/webhook/deliveries` and `POST .../deliveries/{webhook_id}/redeliver` | [Webhooks](#webhooks), this server's own routes (`x-agentrun-serve: "webhook/1"`): the URL run notices are POSTed to, signed by the Standard Webhooks spec; never its secret but once. |
955
+ | `POST /mcp` | This server's own route (`x-agentrun-serve: "mcp/1"`): the [MCP endpoint](#for-coding-agents), Streamable HTTP with one JSON-RPC message per POST (`initialize`, `ping`, `tools/list`, `tools/call`), answered as JSON, stateless. Its ten tools call these routes in process with the caller's token. The Bearer token only, never the page's cookie; a browser `Origin` other than this server's own is `403`; any other method is `405`. |
956
+ | `GET /usage` | The runs' cost estimates, by meter, agent, key, day or region (`key` and `region` are one line, `local`). A run of unknown cost adds no dollars, so no sum is ever null, and is counted in `unpriced_runs` (in the total and in each line) so it never passes as $0. |
957
+
958
+ Home export and import, quotes and `POST /runs/{id}/kill` answer `501 unsupported_here` naming the feature, and
959
+ capabilities declare each one false. No run waits out `input_wait_s` here (`null`), and runs carry no
960
+ browser sign-ins (`sign_ins: false`). `limits.max_cost_usd` is the highest cap a run may name: `null` here, as any cap
961
+ above $0 is taken; it does not mean caps are unsupported ([spend cap](#spend-cap)).
962
+
963
+ ## Uploads
964
+
965
+ A run's input files. Send one in one call, its bytes the body and its path in the query:
966
+
967
+ ```sh
968
+ curl -s "$AGENTRUN_BASE_URL/files?path=plan.md" -H "authorization: Bearer $AGENTRUN_API_KEY" --data-binary @plan.md
969
+ ```
970
+
971
+ It answers `201` with the file, `ready`, under `file`: its `file_id`, `size_bytes` (the body's length) and `sha256`
972
+ (the body's own).
973
+ Its `content_type` is the query's `content_type`, else the request's own type when it names one (not
974
+ `application/octet-stream`, not curl's `application/x-www-form-urlencoded`), else its path's extension's, as a run's files
975
+ are served (`plan.md` is `text/markdown; charset=utf-8`), else `application/octet-stream`. A `sha256` in the query is
976
+ checked against the bytes (`422 input_invalid` when they differ). A multipart form (`curl -F`) is `415`: send the bytes
977
+ themselves. Without `path` a body that is not JSON is `422` at `path`, saying how to call. `Idempotency-Key` replays the
978
+ first file for the same bytes.
979
+
980
+ Or, as the contract has it, in two calls: `POST /v2/files` with the JSON `{path, size_bytes, content_type?, sha256?}`
981
+ reserves the file, `pending`, and answers where to send its bytes, `upload.url`; `PUT` them there as the raw body, any
982
+ content type. Their length must be `size_bytes` and their SHA-256 the `sha256` given (`422 input_invalid` at that
983
+ field), and then the file is `ready`. `upload.url` is a path from the server's root, `/v2/files/{id}`: send it to the
984
+ server's address (`curl -X PUT --data-binary @plan.md "${AGENTRUN_BASE_URL%/v2}$url"`), not after the `/v2` base, where a
985
+ `404` says so. With no `content_type` the reservation's type is its path's extension's.
986
+
987
+ Either way the bytes are streamed to disk, never held whole, so `max_body_bytes` does not apply; a file is at most
988
+ `limits.max_upload_bytes`, 50 MiB (`413`). The same bytes sent again change nothing; other bytes are a `422`.
989
+ `GET /v2/files` lists the server's uploads, pending and ready, newest first (`limit`, `cursor`), `GET /v2/files/{id}` reads
990
+ one's record, and `DELETE /v2/files/{id}` removes it and its bytes (`204`): these three are this server's own
991
+ (`x-agentrun-serve: "files/1"`).
992
+
993
+ A run names up to `limits.max_files_per_run`, 20, ready files in `file_ids`: an unknown, pending or repeated one is
994
+ `422` at `file_ids` before anything starts. Each is copied, never linked, into the run's `work/inputs/` at its `path`,
995
+ folders kept, before the run's process starts, whatever its harness; a name already taken gets a suffix (`notes-2.txt`,
996
+ `docs-2/`), the same for the same files in the same order. The run reads them as any file of its workspace, and
997
+ `GET /v2/runs/{id}/files` lists them. An agentic run is told of them in its first message, on every harness: after the
998
+ input's `content` and a blank line, one line,
999
+ `Files for this run: "inputs/notes.txt" (32 B), "inputs/docs/plan.md" (1.5 KB).`, each file by the path the run's tools
1000
+ take, quoted as a JSON string with a control, format or separator character as its `\uXXXX` escape (so no name forges an
1001
+ entry or reorders the line), and its size, at most 20 and then how many more, and never past what the run's door takes
1002
+ in one message (fewer named, then only how many). That is the message the harness gets, so it is the timeline's first
1003
+ `user_message`; the run's `input` stays as it was sent. A run given no files is sent its `content` as it is. A deleted
1004
+ upload stays in the runs that copied it; a run started after names it in vain. Each upload is kept in
1005
+ `DIR/files/<file_id>/`, 0600. A start clears the temp files a crashed upload left (`.incoming.*.tmp` in `DIR/files/`,
1006
+ `bytes.*.tmp` in a file's folder), each only when it is a regular file (a `DIR/files/` that is a link is not swept), and
1007
+ logs `event=uploads_swept removed=N`. `upload.expires_at`, which the contract requires, is advisory and not enforced in
1008
+ this release: a `PUT` after it is still taken.
1009
+
1010
+ ## Agent home
1011
+
1012
+ Each agent has a home, a directory of its own at `<data>/homes/<key>/`, kept across its runs; runs do not see it yet.
1013
+ The key is the agent's id in lower case and 16 hex digits of the id's SHA-256, so two ids that differ only in case
1014
+ (`keeper`, `Keeper`) never share a home on a disk that folds case, as macOS's does by default. `GET /v2/agents/{id}/home/files` lists every file in it, recursively, in the shape of a run's file list (with
1015
+ `agent_id` in place of `run_id`), and a home never written to lists none. Below it, a file's own path: `GET` reads the
1016
+ file as a run's file is read, and `PUT` writes the raw body as the file, whole (a temporary file renamed over it,
1017
+ `0600`), making the directories on the way and the home itself on the first write, and answers its entry; of two writes
1018
+ at once, the last wins. A body over `capabilities.home.max_file_bytes` (`limits.max_body_bytes`) is `413`.
1019
+ `DELETE` removes a file (`204`; `404` when it is not there) and leaves an emptied directory in place. Paths are checked
1020
+ as a run's are, a write goes at most 16 directories deep (as deep as the list goes), and a link anywhere on the way is
1021
+ never followed: a read is `404`, a write or a delete
1022
+ `403 system_file_forbidden`. `learning/` is the server's alone: the list shows it as one entry,
1023
+ `{"path": "learning", "host_owned": true}`, with none of its notes, and a `GET`, `PUT` or `DELETE` at or under it,
1024
+ however the path is spelled (`./Learning/x`), is `403 system_file_forbidden` (`details.reason` `host_owned`). A read's
1025
+ refusal names the learning API (`/v2/agents/{id}/learning`) on a server that has that route, and on one that does not
1026
+ says `the server keeps learning/ for itself; this server has no learning API yet`. A host-owned name is matched by its
1027
+ first segment folded (compatibility form, any case, no combining marks) and, where that segment and `learning/` are both
1028
+ on disk, by identity (the same
1029
+ device and inode), so a disk that takes another spelling for one name is refused the same way. A path takes only plain
1030
+ segments: each its own NFC form, with no default-ignorable code point, or it is `400 invalid_file_path`. An archived agent's home is read and written as
1031
+ its definition is. A write is held to its directory through `/proc/self/fd`; where there is none (macOS),
1032
+ `capabilities.home.writes` is `false` and `PUT` and `DELETE` are `501 unsupported_here`, as Node has no `openat` to
1033
+ write safely by path, while the list and reads still work. `GET` and `PUT /agents/{id}/home`, the contract's packed home, stay `501`.
1034
+
1035
+ ## For coding agents
1036
+
1037
+ A coding agent (Claude Code, Codex) sets the server up and drives it with
1038
+ [`skills/agentrun-serve/SKILL.md`](skills/agentrun-serve/SKILL.md), shipped in this package. `GET /llms.txt`, at the
1039
+ server's root and without a credential, is the API in brief ([`src/llms.txt`](src/llms.txt)), with no data of the
1040
+ server's.
1041
+
1042
+ `POST /v2/mcp` is the MCP endpoint: Streamable HTTP in its simplest form, one JSON-RPC message per POST answered as JSON,
1043
+ with no stream and no session. Its ten tools:
1044
+
1045
+ | Tool | Routes |
1046
+ | --- | --- |
1047
+ | `whoami` | `GET /capabilities`: the token checked, and what this server runs. |
1048
+ | `agents_list`, `agents_create` | `GET /agents`, `POST /agents` (the arguments are the definition; `definition` carries any other field, checked by the route). |
1049
+ | `agents_revise` | `GET /agents/{id}`, then `PUT /agents/{id}/definition` with the fields given changed, on that revision (`If-Match`). |
1050
+ | `runs_start` | `POST /agents/{id}/runs`, answered at once. |
1051
+ | `runs_get` | `GET /runs/{id}` (its `pending` is a waiting run's question), with `console_url`. |
1052
+ | `runs_events` | `GET /runs/{id}/timeline` with `limit` (100 by default). |
1053
+ | `runs_files` | `GET /runs/{id}/files`, or one file's text up to 64 KiB. |
1054
+ | `runs_respond`, `runs_cancel` | `POST /runs/{id}/messages`, `POST /runs/{id}/cancel`. |
1055
+
1056
+ Each tool calls its routes in process, with the caller's token, so it checks and answers as they do: the route's JSON is
1057
+ the result's structured content (and its text), and a refusal is a result with `isError` holding the route's `error`. A
1058
+ run is started, then polled with `runs_get`; no call is held open for one, and a question a run asks waits as its
1059
+ `input_required` state, for `runs_respond` or a person in the console. The endpoint takes the Bearer token only (the
1060
+ page's session cookie is never taken there), refuses a browser `Origin` other than this server's own, and on loopback
1061
+ refuses a `Host` that is not a loopback name, as every route does.
1062
+
1063
+ ```sh
1064
+ claude mcp add --transport http agentrun "$AGENTRUN_BASE_URL/mcp" --header "Authorization: Bearer $AGENTRUN_API_KEY"
1065
+ codex mcp add agentrun --url "$AGENTRUN_BASE_URL/mcp" --bearer-token-env-var AGENTRUN_API_KEY
1066
+ ```
1067
+
1068
+ ## Harnesses
1069
+
1070
+ A definition names the harness that runs it: `pi` (the default, and what a definition that names none gets),
1071
+ `claude-agent` or `codex`; any other is `422 input_invalid` on `definition.harness`. Every answer names it. An edit
1072
+ (`PUT /agents/{id}/definition`) that names no harness keeps the agent's, as it keeps its skill files; name `pi` to move it
1073
+ back.
1074
+ `GET /v2/capabilities` lists each in `harnesses`, with `available` and, when not, the `reason`, and `default_model`: the
1075
+ model the harness runs when a definition names none (`provider/model-id`, as a save and a run resolve it), or null where
1076
+ it runs none (the harness does not run here, or no default model here runs on it: claude-agent never takes a gateway's
1077
+ model). A definition naming a
1078
+ harness this server does not run yet saves with a warning on `definition.harness`, and a run of it is
1079
+ `409 agent_not_runnable` with `details.harness`; it never runs on pi instead. This server runs pi always, and
1080
+ `claude-agent` and `codex` when each adapter's package, pins and provider endpoint check out; the harness's `reason`
1081
+ says what is missing. The packages and pins are checked once, at the start (`event=harness_offers why=start`): a harness
1082
+ installed after it, or put back on its pinned build, stays unavailable until AgentRun restarts, and its reason ends
1083
+ saying so, `once it is installed, restart AgentRun to pick it up` or `once the pinned build is installed, restart
1084
+ AgentRun`. Run from npx, a reason whose install line is the npx line that starts the server with what is missing needs
1085
+ no such clause: running that line is the restart. A reason a setting fixes (a model key, say) names no restart.
1086
+
1087
+ `claude-agent` sends its requests to `ANTHROPIC_BASE_URL` (else Anthropic) with `ANTHROPIC_API_KEY` and Anthropic's own
1088
+ model id, and prices the run by it: a revision's `anthropic/<model-id>`, its dots as dashes, so OpenRouter's dotted name
1089
+ (`anthropic/claude-sonnet-5.5`) and Anthropic's own (`claude-sonnet-5-5`) are one model. `codex` sends its requests to
1090
+ serve's gateway (`AGENT_MODEL_BASE_URL`), else OpenAI with `OPENAI_API_KEY`. A harness with none of its own settings, where
1091
+ `OPENROUTER_API_KEY` is set, runs through OpenRouter (`https://openrouter.ai/api`, the key as a bearer token):
1092
+ claude-agent on its Messages endpoint, with Anthropic's own id on the wire (OpenRouter takes it: its Claude Code guide
1093
+ says its "Anthropic Skin … handles model mapping") and the run priced by OpenRouter's catalog entry; codex on its Responses API, with the model's whole id (`openai/gpt-6-sol`). On that key alone the defaults are
1094
+ `openrouter/openai/gpt-6-sol` for pi (pi-ai's OpenRouter provider, on the bearer route), `anthropic/claude-sonnet-5.5` for
1095
+ claude-agent and `openai/gpt-6-sol` for codex; a direct provider's key gives the default for its harnesses where it is
1096
+ set. A model named `openrouter/<vendor>/<model>` (pi's name for it) goes through OpenRouter on every harness. An endpoint
1097
+ the host names never gets OpenRouter's key: `ANTHROPIC_BASE_URL` without `ANTHROPIC_API_KEY` is refused. A model with more
1098
+ than one segment after its provider (`anthropic/anthropic/claude-sonnet-5.5`) is refused, naming the form to use. A provider
1099
+ that refuses the run's key (401) fails the run naming the key and where to set it ("OpenRouter refused
1100
+ OPENROUTER_API_KEY (401: User not found): set it where AgentRun starts, or save it in Settings → Model keys."), on every
1101
+ harness, with the provider's first sentence only.
1102
+
1103
+ `claude-agent` loads the revision's skills itself: the model is shown each as `agentrun:<name>`, loads one with the Skill
1104
+ tool and reads its other files with `read_skill_file`, and the system prompt holds the instructions alone. A skill the
1105
+ adapter does not take (a name that is not lowercase letters, digits and dashes, a `SKILL.md` without front matter giving
1106
+ its `name` and a `description`, a file path that is not plain or is deeper than five segments) stays inlined in the
1107
+ system prompt, as every skill is on `pi` and `codex`; so do all of them when together they hold more than 1 MiB.
1108
+
1109
+ `definition.harness` and `capabilities.harnesses` are this server's, outside the `agentrun.v2/0` contract:
1110
+ `GET /v2/openapi.json` marks each `x-agentrun-serve: "harness/1"`, beside the other properties it adds (`model/1`,
1111
+ `serve/1`), and lists them in `info.x-agentrun-serve.fields`.
1112
+
1113
+ ## Decision workflows
1114
+
1115
+ A workflow's typed questions (its `judge`, `pick`, `sift`, `route` and `ask` nodes) run on a decision provider when
1116
+ this server's environment sets the provider's key. They are fast decisions, not agent turns: one request per node, with
1117
+ typed answers and their probabilities.
1118
+
1119
+ - Jev, TypeSafe's System One, through `@parcha/agentrun-jev`, answers a node that names no provider. Set
1120
+ `TYPESAFE_API_KEY`: it is the route whose key stays out of a run's reach (below). `OPENROUTER_API_KEY` also works,
1121
+ for Jev through OpenRouter, and so does a model gateway on OpenRouter: with `AGENT_MODEL_BASE_URL` on the host
1122
+ `openrouter.ai` and neither key set, Jev runs on `AGENT_MODEL_API_KEY`.
1123
+ - Parallel Decisions, through `@parcha/agentrun-decisions`, answers a node that says `provider: "parallel"`, with web
1124
+ citations as its evidence. Set `PARALLEL_API_KEY`. Each request is booked at Parallel's list price as an estimate,
1125
+ and one whose outcome was lost after sending is never sent again: the run escalates it as interrupted.
1126
+ - OpenRouter's Decisions models answer a node that says `provider: "openrouter"` and names its model in `model`
1127
+ (`liquid/d1`, `perplexity/pplx-decider-v1.2`, `cloudflare/clef`, `typesafe/jev-1.14`). They run on the OpenRouter key
1128
+ Jev's OpenRouter route reads (`OPENROUTER_API_KEY`, else `AGENT_MODEL_API_KEY` with `AGENT_MODEL_BASE_URL` on
1129
+ openrouter.ai), handed to the run's process on the decision descriptor as Jev's is. That key is also the model
1130
+ gateway's, which a run's process holds. Images to them are experimental.
1131
+ - A decision node's `images` are files of the run's `work/`, such as the pages `pdf_pages` draws: the run's process
1132
+ reads them and sends them with the request. The receipt keeps each image's SHA-256, never its bytes.
1133
+ - `GET /capabilities` lists the providers in `workflows.decisions.providers` (`[{id: "jev" | "parallel" | "openrouter", available,
1134
+ reason?, note?}]`), and `runJudge` is among `workflows.adapters` once any of them runs here. On the OpenRouter route,
1135
+ jev's `note` names the variable Jev runs on (`OPENROUTER_API_KEY` or `AGENT_MODEL_API_KEY`) and says that it is the
1136
+ model gateway's key.
1137
+ - With no key for a provider a workflow's nodes name, the workflow saves with a `not_set_up_here` warning on
1138
+ `definition.workflow` naming the variable, and a run of it is `409 agent_not_runnable`, with `details.adapters:
1139
+ ["runJudge"]` and `details.decisions` naming each missing provider, for example `{parallel: {reason:
1140
+ "not_set_up_here", needs: ["PARALLEL_API_KEY"]}}`. A provider this server does not have refuses the save, `422`.
1141
+ - Each question's receipt is a row of the run's store (`agentrun.decisions`) before its answer acts, and a resumed run
1142
+ takes an answered one instead of asking again.
1143
+ - Jev's API reports token counts and no price, so each answered decision is booked at TypeSafe's published price
1144
+ ($0.042 per million input tokens; output tokens are free) as an estimate, and the run's `cost.usd` is its decisions'
1145
+ sum, with `basis: "estimate"`. A decision whose cost is unknown (no token counts, the OpenRouter route, or a call that
1146
+ failed after it may have been sent) keeps its receipt's cost `null`, and the run's reads `null`, never `0`.
1147
+ - The TypeSafe and Parallel keys never enter a run's environment, which its tools and its model's provider read. The
1148
+ server drops `TYPESAFE_API_KEY` and `PARALLEL_API_KEY` from every run's process. It hands a run's process those it
1149
+ needs ([Safety](#safety)), a workflow's decision providers' and Parallel's where its `web_fetch` or `web_search`
1150
+ resolves to Parallel, once, by name, on an inherited pipe (the first descriptor after its stdio and its secrets pipe, as macOS refuses a high one), at each
1151
+ launch, a resume after a restart included. The process reads them once into its decision providers and web tools,
1152
+ closes the descriptor before anything else runs, and keeps the keys nowhere else. It is never in an
1153
+ environment, an argument list or a file, and no program the run starts inherits it. With no key, no descriptor is
1154
+ opened. On the OpenRouter route Jev's key comes on the same descriptor, never from the run's environment; that key is
1155
+ also the model gateway's key, which a run's process holds for its model nodes.
1156
+ - `TYPESAFE_API_KEY` and `PARALLEL_API_KEY` are among the secrets the launcher hands the server over its pipe, so the
1157
+ server holds them out of its own environment too. Neither is ever among the secrets a run's process gets over its own
1158
+ pipe, which are its tools' environment: the decision descriptor is their only way into a run.
1159
+
1160
+ ## Archiving
1161
+
1162
+ An agent or a run is archived, never deleted: `DELETE` stays `405`. These routes are this server's own, outside the
1163
+ `/v2` contract, like `GET /runs` and an agent's revisions; capabilities list them in `features.archive`.
1164
+
1165
+ - `POST /v2/agents/{id}/archive` hides the agent and its runs from `GET /agents`, `GET /runs` and
1166
+ `GET /agents/{id}/runs`; `POST /v2/runs/{id}/archive` hides one run. `.../unarchive` shows them again. Each is
1167
+ idempotent (archiving again keeps the first time), takes no body, and answers what it changed.
1168
+ - Each list takes `archived=true` to list only archived ones (`false`, the default, lists the others).
1169
+ - Every read by id still answers, with `archived_at` (null when it is not archived; a run's is its own, else its
1170
+ agent's): `GET /agents/{id}`, `GET /runs/{id}`, its timeline and its files. `/usage` still counts archived runs: the
1171
+ spend happened.
1172
+ - A new run of an archived agent is `409 agent_not_runnable`, saying it is archived (`details.archived_at`); a run
1173
+ already going when its agent is archived keeps going.
1174
+ - The store keeps each change as one row of `archive_changes` in `store.sqlite`, written once
1175
+ ([the store](../pi-durable-agent/README.md#agents-in-a-folder-the-agent-store)). A data directory an earlier version
1176
+ wrote opens as it is, with nothing archived. Going back to an earlier version keeps every row, but that version does
1177
+ not read them: archived agents and runs show as not archived there, and an archived agent's runs start again.
1178
+
1179
+ ## The console
1180
+
1181
+ Open the link the server prints, once, in a browser. `/` is the console (`apps/console` in the repository), on the
1182
+ server's own origin, under a CSP that allows that origin only:
1183
+
1184
+ - **Mission Control**: the store's counts and the latest runs.
1185
+ - **Agents**: each agent with its kind and harness, archived ones behind **Archived**. **New agent** and an agent's page:
1186
+ a name, a description, a prompt (with its model, thinking level and tools) or a workflow, sent to `POST /v2/agents`;
1187
+ an edit is `PUT /v2/agents/{id}/definition` with `If-Match` set to the revision it started from (412 when another came
1188
+ first). Its revisions, with **Make current** (`POST /v2/agents/{id}/current`), and **Archive** or **Unarchive**.
1189
+ - **Playground**: a run of an agent, on the revision you pick, with its input, followed as it goes.
1190
+ - **Runs**: every run, newest first, filtered by agent and by state, archived runs behind **Archived**; the address
1191
+ keeps the filters. A run's page follows `GET /v2/runs/{id}/timeline` with a long poll, sends messages (an answer while
1192
+ it waits on `ask_person`), stops or cancels the run, shows its files and a workflow's graph, and has **Archive** or
1193
+ **Unarchive**.
1194
+
1195
+ Its files (`index.html`, and Vite's hashed files under `/assets/`) are public and hold no data: everything it shows
1196
+ comes through `/v2`. The store's read-only JSON stays under `/api/*` (`/api/store`, `/api/agents/{id}`, `/api/runs` and
1197
+ the rest of [`@parcha/pi-durable-agent`](../pi-durable-agent/README.md#looking-at-a-store)'s store page's data), for a
1198
+ script with the token or a browser with its cookie. With accounts on (the default) the console asks for the owner's password
1199
+ ([your password](#your-password)) and the browser holds the owner's session cookie; a `?token=` link sets no cookie: the
1200
+ token is for scripts and the CLI. With `AGENTRUN_ACCOUNTS=0`, the printed link (`/?token=`) sets a cookie (`HttpOnly`,
1201
+ `SameSite=Strict`, `Path=/`, and `Secure` when `X-Forwarded-Proto` says https) and sends the browser to the same address
1202
+ without the token. The cookie's value is derived from the token, never the token itself, and it lasts until the browser
1203
+ closes. Without it, the console says to open the link. Either cookie takes the place of `Authorization: Bearer` on
1204
+ `/api/*` and `/v2`: for a `GET`, and for any other method only when the request's `Origin` is the server's own origin
1205
+ and its body is `application/json`, or, on a `PUT` or `POST` to a route that takes bytes (`PUT /v2/files/{id}`,
1206
+ `POST /v2/files`), of any content type. A request that sends an `Authorization` header is checked on that header alone.
1207
+
1208
+ The repository's `npm ci && npm run build` builds the console (`apps/console`) first, and the server's build copies it
1209
+ into `dist/console`; the image always carries it. A server built without it answers `/` with a 404 that says so. `/console/`
1210
+ (the console's address before) and `/setup` and `/sign-in` (the old page's, which the printed setup link still names)
1211
+ send the browser to `/`, which keeps a link's `#code`.
1212
+
1213
+ ## Your password
1214
+
1215
+ AgentRun Server is for one person, who signs in to the console with a password (`AGENTRUN_ACCOUNTS=0` turns this off). With
1216
+ no `AGENTRUN_PUBLIC_URL`, the start prints `Set your password: <url>/setup`, and the first visit sets it, 12 characters or
1217
+ more. With it, the start prints `Set up this server: <url>/setup#code=<code>`, and setup takes that code (or the token as
1218
+ the Bearer). The server keeps a scrypt hash of the password, never the password, in `DIR/owner.json`, and signs its
1219
+ session cookies with the key in `DIR/.session-secret`; both are 0600, and no run reaches either. A session lasts 30 days;
1220
+ **Sign out everywhere** ends every session on every browser. Sign-in tries are limited per address, ten in 15 minutes, and the limit keeps up to 10,000 addresses: past that a
1221
+ new address gets a 429 until older ones expire, and an address already limited stays limited. Forgot it: run
1222
+ `agentrun-serve reset-password --data DIR` where the data directory is (`docker exec agentrun node
1223
+ /opt/agentrun/packages/serve/dist/cli.js reset-password --data /data` in the image). It clears the password and signs every
1224
+ browser out, and the next visit sets a new one. The token works for scripts and the CLI either way.
1225
+
1226
+ A browser's writes must come from the server's own origin. Serve the image on another address or port behind a proxy, and
1227
+ set `AGENTRUN_PUBLIC_URL` to the address people open. Behind a proxy every sign-in comes from the proxy's address, so the
1228
+ limit is one for everyone: ten wrong tries in 15 minutes, from anyone, keep the owner out until the window passes (the
1229
+ token still works for scripts meanwhile). Serve it over https where you can: on plain http a browser sends the session
1230
+ cookie to every server on the same host name, whatever its port, so another app on that host could read it.
1231
+
1232
+ ## Importing your sessions
1233
+
1234
+ `agentrun-serve import --data DIR` reads the Claude Code, Codex and pi sessions in your own home (`~/.claude/projects`,
1235
+ `~/.codex/sessions`, `~/.pi/agent/sessions`) into the data directory, once. Each project folder becomes an agent, with its
1236
+ CLAUDE.md or AGENTS.md and its skill folders, and each session becomes a run you can read but not continue. Nothing leaves
1237
+ this machine, and the values of key-shaped environment variables are cut out of what it writes. Run it again and it takes
1238
+ only what it has not taken already. Sessions written in the last 10 minutes wait for the next import.
1239
+
1240
+ - `--dry-run` lists what it would import and writes nothing.
1241
+ - `--from claude-code,codex,pi` picks the sources.
1242
+ - `--include-deleted` also imports the sessions of project folders that no longer exist, such as a git worktree you
1243
+ deleted. Each such folder is still its own agent, with no instructions or skills to read.
1244
+ - `--all` keeps those too, as well as sessions of temporary folders and sessions with no message of yours.
1245
+ - `--verbose` lists each file it leaves out, and why.
1246
+
1247
+ The dry run and the import both end by counting what they left out, by why, with the flag that brings each kind in:
1248
+
1249
+ ```
1250
+ left out: 84 sessions from folders that no longer exist (--include-deleted imports them too)
1251
+ left out: 2 sessions still being written: they come in next time
1252
+ ```
1253
+
1254
+ ## A run's life
1255
+
1256
+ 1. `POST /agents/{id}/runs` starts the run in the store (`startRun`, which pins the revision and seeds
1257
+ `DIR/runs/<id>/`), then its process: `pi-durable-disk run --dir DIR/runs/<id> --app <this package's app> --serve 0` on
1258
+ loopback, behind a token of its own (`DIR/.door-token`), with its stderr in `runs/<id>/process.log`. The run's input
1259
+ is in `runs/<id>/serve.json`.
1260
+ 2. The app reads the run's revision from the store.
1261
+ - An agentic revision runs as the root agent: its instructions and skills, its model, and the tools it names of the
1262
+ workspace's `read`, `write` and `edit`, and `ask_person`, which ends the turn; the timeline then shows a `waiting`
1263
+ row, and the run is `input_required` and `waiting` until a message answers it. `bash` is bound only in a
1264
+ [sandbox](#sandbox), where it and the file tools run in the run's box. The run is `queued` until its first message shows; while the process runs, the
1265
+ timeline comes from its door's events through `@parcha/pi-durable-agent/timeline`. Once the run is idle and its
1266
+ newest row is the agent's answer, the server sends the process SIGTERM. A model error ends it `failed`
1267
+ (`run_failed`), and a run its `max_cost_usd` stops ends `failed` (`spend_cap_reached`, [below](#spend-cap)).
1268
+ A stop sent while the run still reads `queued` (a message sent to it not yet in its timeline) waits, up to a
1269
+ request's deadline, for that message to show, then stops the turn as it stops any working run.
1270
+ A stopped run can be continued: a follow-up starts a fresh turn on the whole history, and the turn the stop cut is
1271
+ not replayed. A cancelled run cannot: a message to it is `409 not_continuable`, and its `next_action` is to start a
1272
+ new run of the agent.
1273
+ - A workflow revision runs on agentrun-pi's durable workflow task, started by `startWorkflowRevision` of
1274
+ `@parcha/pi-durable-agent/workflow` (keyed by the run's id): its model nodes (`agent`, `decide`, `extract`,
1275
+ `report`) on the run's model, with the file tools each node names, and its typed questions on Jev or Parallel
1276
+ ([decision workflows](#decision-workflows)). A workflow that needs code or a tool call this host does not run is
1277
+ not saved here (`422`). The run is `queued` until its process serves, then `working`; when the workflow
1278
+ ends, the app writes the run's final status with the outcome and releases it. Nothing is carried back from inside
1279
+ the process, which holds the run's store until it exits.
1280
+ 3. When the process has exited, the run's rows are read from its released store (an agentic run's conversation, a
1281
+ workflow run's model nodes), and the server carries the run back, every run of both kinds: `carryBack` records its
1282
+ state, cost and a summary in the store (an agentic run's answer; a workflow run's `workflowCarry`, its completed
1283
+ nodes, then where it failed or escalated). Its last
1284
+ page says `final`. v2's `cancelled` is the store's `stopped`; a workflow that escalated ends `failed` with
1285
+ `error: {code: "escalated", message: <its summary>}`, in the run and in the lists.
1286
+ 4. When the server starts, it reads every run the store says is running. A run process an earlier server started and
1287
+ that still serves the run is supervised again, by its `run.json` and its pid; a run that already ended is carried
1288
+ back; a run whose process is gone before it ended is opened again on its directory and resumes from its store (an
1289
+ agentic run waiting for an answer waits without one, until a message). A carry back that finds the store held by
1290
+ another writer is tried again with backoff, and at the next start.
1291
+
1292
+ An `Idempotency-Key` answer is kept in `DATA/.idempotency.json` for `limits.idempotency_ttl_s` (a day), written before
1293
+ the answer is sent, so a retry after a restart gets the first answer.
1294
+
1295
+ A completed agentic run's `result` is `{output: null, final_answer}`; a completed workflow run's is
1296
+ `{output: <the workflow's output>, final_answer: null}`.
1297
+
1298
+ ## Learning
1299
+
1300
+ Learning is off unless an agent's definition says `learning: true` (an agentic one: a workflow refuses the field). A
1301
+ definition that sets it keeps it on its revision, `false` included, and an edit that leaves it out keeps the agent's; one
1302
+ that never sets it stores nothing, so its revision id is the one it had before the switch. The server's `--learning off`
1303
+ turns learning off for every run it starts, whatever the agent says.
1304
+
1305
+ An agent that learns has a learning folder, `learning/` in its home (`DATA/homes/<key>/learning/`), in Claude Code's
1306
+ auto-memory format:
1307
+
1308
+ - `MEMORY.md`, the index a run reads, one line per active note: `- [name](file.md) — description`, built by the server;
1309
+ - one file per note, `<slug>.md`: front matter with `name`, `description` and `type` (`user`, `feedback`, `project` or
1310
+ `reference`), and optionally `status: superseded` or `retired` with `superseded_by` (no status: active), then the
1311
+ note's text. The server parses it and builds the index with its own code, in [`src/learn/`](src/learn/SPEC.md),
1312
+ whose `SPEC.md` is the folder's contract.
1313
+
1314
+ The folder is plain git with `main` checked out. The agent's first run that learns makes it, with one commit on `main`
1315
+ holding an empty `MEMORY.md`; an agent that does not learn never gets one. The server is its only writer. Every git
1316
+ call the server makes there runs with the folder's hooks and fsmonitor off, no replace refs, no lazy fetch and no system
1317
+ or global config, one at a time per agent.
1318
+
1319
+ Each run of an agent that learns starts from `main` as it is when the run is made, whatever its harness:
1320
+
1321
+ - `runs/<id>/learning.json` pins that commit (`seed`). It is written once: a resume or a follow-up reads the same
1322
+ commit, however `main` moves on.
1323
+ - What the agent learned goes into the run's instructions after the agent's, under `# Learned`, so a run reads it
1324
+ whatever its tools: an agent with no `read` tool still follows its notes. Only active notes are served: a note with
1325
+ any other status is never there, whole or by its index line (one a hand edit left in `MEMORY.md` is dropped), and is
1326
+ not counted toward the budget. Each active note is there whole (its
1327
+ `## name (file.md)`, its description, then its text), the one changed last on `main` first (a merge or a person's
1328
+ edit; then by name), while they all fit the server's learning budget (`--learning-budget`, 8000 bytes by default).
1329
+ Past it, the run reads the first 200 lines of `MEMORY.md` (and no more than 25 KB, as Claude Code loads its own),
1330
+ then the notes changed last, whole, while they fit what is left; the rest are named only in the index, and an agent
1331
+ with the `read` tool is told they are in `.learning/`, to open one when it applies (one without is not). A line
1332
+ before them says to follow a note when it applies. `# Learned` opens, for every run that learns, notes or none, with
1333
+ what the run is told of learning: that only what it answers when it is asked at the end is kept, never a file it
1334
+ writes, so it tells the person it will keep what they ask it to remember, and that a secret is never kept. A run with
1335
+ nothing learned yet is told so. A run that does not learn (or whose seed failed) gets no `# Learned`. Every name, description, text and index line is cut of the server's secrets as they are when the run is made,
1336
+ as a person's reads are. That is pi's system prompt and claude-agent's and codex's instructions: the same channel
1337
+ `CLAUDE.md` and `AGENTS.md` travel in. No such file is written into the run's work (claude-agent keeps project
1338
+ settings off, so a `.claude/` in the work never loads). The pin keeps the section the run
1339
+ reads (`section`), so a resume or a follow-up reads the same; a pin an earlier server wrote, the index alone
1340
+ (`learned`), is read as that server gave it.
1341
+ - `MEMORY.md` and the active notes are copied into the run's `work/.learning/`, made fresh and cut of the server's
1342
+ secrets the same way, for the run to read; a note that is not active is not, and neither is its line in the index.
1343
+ - The skills the agent wrote, each a folder `skills/<name>/` on `main` with its `SKILL.md`, join the revision's own:
1344
+ each is copied, every file of it, into the run's `work/.agents/skills/<name>/`, and the run gets it as it gets the
1345
+ revision's (pi and codex read each `SKILL.md` in their prompt, claude-agent loads the ones its adapter takes through
1346
+ its Skill tool). A skill named like one of the revision's is the revision's, and only an active skill is served: one
1347
+ whose `SKILL.md` front matter says `status: pending` (held for its owner's OK), or any status but `active`, is not.
1348
+ The learned ones get 256 KiB, every file of each together, and never more than the revision's skills leave of the 1
1349
+ MiB an adapter takes of a run's skills in all, so they never push the revision's back into the prompt: the one
1350
+ changed last on `main` first, each whole while it fits. One that does not fit, or holds one of the server's secrets,
1351
+ is left out. The pin names the files of the ones laid (`skills`) and the ones left out (`skills_left_out`), and a
1352
+ follow-up gets them laid again, fresh, whatever the run wrote over them; one the work no longer holds whole when the
1353
+ run's process starts is left out of what its harness gets, and the run goes on. A skill whose name or files are out
1354
+ of shape is not read, and a symbolic link or a submodule at `skills/` or anywhere under it is a learning fault.
1355
+
1356
+ The server reads the commit with git plumbing, never the working tree. What it holds that is not a regular UTF-8 file of
1357
+ 1 MiB or less, or a note out of shape, is not read, and the server's stderr names it. A learning fault never blocks a
1358
+ run: when the folder cannot be made or read, or its notes copied, the run starts with nothing learned. A host without
1359
+ git 2.40 or later is one such fault, said once on stderr.
1360
+
1361
+ ### What a run learns
1362
+
1363
+ When a run that learns answers or fails, the server asks the same session one more turn before it lets the run go,
1364
+ whatever its harness and whatever tools its agent has: one message through the run's door under the fixed request id
1365
+ `learn-reflect-<run id>`, so a server that restarts mid-turn asks again and the run takes it once. The server alone
1366
+ sends it, with the origin `reflect`; no request field sets it. The message (`reflectPrompt`, in `src/learn/reflect.ts`)
1367
+ asks the agent to look back over the whole conversation, what the user asked it to remember included, and to answer
1368
+ with each note to keep as one ` ```note <file>.md ` block in the note format, and to use no tool: no `write` tool is
1369
+ needed, and nothing the run wrote in `work/.learning/`, during the task or the turn, counts. It also says that a memory
1370
+ is replaced by a new note with `supersedes: [old.md]` and never by reusing a name, how many index lines are left (200
1371
+ less the active notes), that `No notes.` is a fine answer, and what not to keep. The turn runs under the run's own cap,
1372
+ with no reserve, and within 5 minutes; its rows are labelled `learning`, and the run's answer stays the job's.
1373
+
1374
+ As the run settles, before it reads ended and before a follow-up can open it again, the server keeps what the turn
1375
+ answered, the whole text of each of its messages, and what the user said in the run, in `runs/<id>/learning-turn.json`.
1376
+ Once the run has ended, in the agent's queue, the server reads the notes from that answer alone (`parseReflection`, in
1377
+ `src/learn/reflect.ts`): an answer with no note is `empty`, and one that gives notes out of format (a note outside a
1378
+ block, a block not closed, with no file name, or a name given twice) is `unparsed`, nothing kept. `checkProposal`
1379
+ (`src/learn/check.ts`) then refuses, before anything is written anywhere, a note that reuses an existing note's name, a
1380
+ path that is not a `.md` file at the top, a bad name, front matter out of shape or setting `status`, a `supersedes`
1381
+ naming a note that is not active, more than 8 notes superseded, more than 8 new notes or a note over 4068 bytes (4096,
1382
+ less the 28 the server's own `origin` and `status` lines may take once it merges the note), an
1383
+ index past 200 lines, hidden characters, and text shaped like a secret or holding one of the server's own secrets (the
1384
+ launcher's, the keys and tokens in its environment, its API and door tokens), in a note or its name. A `MEMORY.md` the
1385
+ answer gives is ignored. What passes is kept as the run's proposal, `runs/<id>/learning-proposal.json`, with what the
1386
+ user said, each message cut of the server's secrets.
1387
+
1388
+ Then one grader decides, one grade at a time per agent: `gradePrompt` (`src/learn/grade.ts`), which holds
1389
+ `GRADE_RUBRIC`, the rubric's one statement, bounded (3 minutes), against `main` as it is then, and read by
1390
+ `parseVerdict`, which fails closed. It runs on the model the server grades on: `--grade-model` (or
1391
+ `AGENTRUN_SERVE_GRADE_MODEL`), else the strong tier (`AGENT_MODEL_STRONG`), named as the strong tier takes one; with
1392
+ neither, on the agent's own model. `GET /capabilities` names it as `learning.grade_model` (null for each run's own). A
1393
+ cheap model is a poor grader, so point the strong tier (or `--grade-model`) at a strong one. The grader reads each active
1394
+ note's index line, the whole text only of the notes the proposal supersedes, what the user said in the run (cut of the
1395
+ server's secrets, as the proposal keeps it), and the new notes, so its prompt stays under 200,000 characters however
1396
+ many notes the folder holds. Only with Jev's key here does an injection screen
1397
+ run first, on Jev: a note it scores at `INJECTION_THRESHOLD` (0.75) or over, or cannot score, drops the run. What the
1398
+ grade spends is in no run's totals: it is kept on the run's learning, and counted once on `GET /usage` under the meter
1399
+ `learning`, by agent and by day; a call cut off at its bound spent what nobody knows, so its cost is unknown, never $0.
1400
+
1401
+ A kept verdict merges as one commit on `main`, made with plumbing: the new notes added, each with its `origin` (`you`
1402
+ for what the user asked in their own words, `run` for what the run worked out), each note they supersede marked
1403
+ `status: superseded` with `superseded_by`, `MEMORY.md` rebuilt from the active notes, and the checked-out files brought
1404
+ in line. A risky rule (to trust a site or a seller, skip or loosen an approval or a check, or send money or data to
1405
+ an account), whether the user asked for it or the run worked it out, is merged as `status: pending`: in no `MEMORY.md`
1406
+ and no run's copy, to wait for its owner's OK, and named on the run's learning (`pending: [{file, name}]`, detail
1407
+ "Waiting for your OK: <name>.", after what it learned when it kept one too).
1408
+ `GET /capabilities` says so (`learning.pending: true`). Its message is `learning: <run id>: merged`, the grader's reason and a `Run-Id` trailer; `main` moves only from
1409
+ the commit the merge was made on (once more on a `main` that moved meanwhile), and a run a trailer already names is
1410
+ merged, never twice. The merge's own questions are asked again of `main` first: a name another run added since is
1411
+ refused as `exists`. A server that goes between steps picks the run up at its next start, once.
1412
+
1413
+ The run's `learning` (on `GET /runs/{run_id}`, and `{state, reason, detail}` in run lists, the detail cut to 140
1414
+ characters and no time) says how it went: `seeded`, then
1415
+ `reflecting` during the turn and until what it answered is checked, `proposed` while it is graded, and `merged`, or
1416
+ `dropped` with a reason from a closed list (`seed_failed`, `no_budget`, `unknown_cost`, `cancelled`, `crashed`,
1417
+ `reflect_timeout`, `reflect_failed`, `empty`, `unparsed`, `propose_failed`, `checker`, `screen`, `screen_down`,
1418
+ `grader`, `grade_failed`; `no_write_tool` and `tool_denied` are an older server's, still read and counted, and no run
1419
+ gets them now). It is `null` for a
1420
+ run that does not learn (its agent's `learning` is not true, the server's switch was off when it started, or it is a
1421
+ workflow's or an imported run). Its `detail` says the same in a person's words, never the machine's: "Started from 2
1422
+ notes.", "Looking back on this run…", "Checking 1 new note…", "Learned: Check units (replaces 1 older note)", "Learned:
1423
+ Check units. Waiting for your OK: Buy from PaperDepot24 first.", "Nothing new to remember from this run.", "Not kept: <the
1424
+ grader's reason, its first sentence>", "Not kept: it held something that must not be stored (one of this server's
1425
+ secrets).", "Not kept: its notes weren't in the expected format.", "Not kept: learning stopped (looking back took too
1426
+ long)." and so on (`learning-words.ts`); a client that acts on it reads `state` and `reason`. A note's name or the
1427
+ grader's reason in it is said again at each read from what the run keeps (its `learned` and `pending` notes, the
1428
+ grader's verdict), cut of the server's secrets as they are then before the words are cut short (300 characters, 140 in a
1429
+ list), so a value that became a secret after the run is never shown in part. Once it is proposed, merged or dropped (`seed_failed` included), the run's
1430
+ timeline has one row of kind `learning` whose summary is that detail.
1431
+
1432
+ Three more fields say what the run used, learned and holds for the owner's OK (`learning/2`), on its read and in run
1433
+ lists alike, each absent when it holds no note: `used`, `[{file, name}]`, the notes its job read from `.learning/`,
1434
+ found once as the run settles from its timeline (each `read` call on any harness whose result was a success, of a note
1435
+ the run started from: never `MEMORY.md`, nor a read its end-of-run turn made, nor a note read through a command such as
1436
+ `bash`'s `cat`) and kept in `serve.json`, so a list never reads a timeline; `learned`, `[{file, name, supersedes}]`, the
1437
+ notes its merge added, once `merged`; and `pending`, `[{file, name}]`, the notes its merge holds for the owner's OK, once
1438
+ `merged`, never among `learned`. A name and a file are cut of the server's secrets as they are now, a file holding one
1439
+ `[redacted]`.
1440
+
1441
+ Each run's learning end is written once to the learning ledger, `DATA/learning-usage.jsonl`, one line `{run, agent,
1442
+ state, reason, at, cost, tokens, seed_notes, answered_at, job_cost_usd, look_back_usd}` (`cost` and `tokens` the
1443
+ grade's, null when unknown, 0 when nothing was graded; `seed_notes` how many notes the run started from; once it looked
1444
+ back, `answered_at` and `job_cost_usd`, when its job's answer was final and what it had cost then; `look_back_usd` what
1445
+ looking back cost, 0 when it did not), after its `serve.json` holds it; a server that went between the two writes it at
1446
+ its next start. `GET /stats` counts the runs that tried to learn under `learning`, over its `from`, `to` and
1447
+ `agent`, from that ledger and from the runs the server holds (`in_progress`), never opening a run's files; the
1448
+ `learning` meter on `GET /usage` reads the same lines.
1449
+
1450
+ An eval set of 20 runs and what each proposed, labelled keep or drop (`test/fixtures/learn-eval.json`: lessons the
1451
+ agent worked out, user preferences and a "remember" during the task, one-shop facts, secrets, a tool's failure and four
1452
+ injections), runs in CI through the parser, the checks and the grader's prompt on a faux grader that answers by label
1453
+ (`test/learn-eval.test.mjs`). `scripts/learn-eval.mjs` runs the same set on real models, the grade and the end-of-run
1454
+ turn both, and prints keep-precision, keep-recall and the injection-drop rate per model; it spends.
1455
+
1456
+ ### What a person sees and controls
1457
+
1458
+ A person reads and changes an agent's learning through this server's own routes (`learning/1` in `/v2/openapi.json`),
1459
+ with the token, an archived agent's too:
1460
+
1461
+ - `GET /agents/{agent_id}/learning`: `main`'s head, `MEMORY.md` as `index`, the first 50 notes (active first, then
1462
+ newest first) and the first 20 changes on `main` (newest first, each `by: {run}` from its `Run-Id` trailer or
1463
+ `{user: true}`, with its commit, time, reason and files), and how the agent's runs that tried to learn fared
1464
+ (`merged`, `dropped` by reason, `in_progress`), counted as `GET /stats` counts them: from the learning ledger and the
1465
+ runs the server holds, never a run's files; and `impact` (`learning/2`), what learning changed: the agent's completed
1466
+ runs that started from at least one active note against those that started before its first note (the earlier of its
1467
+ first merge and the start of its first run that started from a note, so a person's first note counts), each side's
1468
+ `runs`; `median_duration_s`, the time to the answer (the run's start to its job's end, before it looks back);
1469
+ `median_cost_usd`, the job's own cost without its look-back, over the `cost_runs` whose cost is known; and
1470
+ `median_learning_usd`, what learning itself cost a run (its look-back and its grade). From the same rows and ledger;
1471
+ null unless both sides count 2 runs. An agent with no folder answers `main: null`, empty pages and `impact: null`.
1472
+ `GET .../learning/notes?cursor=&limit=&status=` and `GET .../learning/log?cursor=&limit=` page on, up to 200 at a
1473
+ time; a cursor reads the same commit its first page did.
1474
+ - `GET .../learning/files/{file}`: one note (or `MEMORY.md`) on `main` as `text/markdown`, with its `ETag`, the note's
1475
+ git blob id.
1476
+ - `PUT .../learning/files/{file}` with the note's whole text (as `text/markdown` or `text/plain`, or as
1477
+ `application/json` `{text}`, the form the console's page sends under its session) edits it under `If-Match: <etag>`,
1478
+ or creates it under `If-None-Match: *` (201); `POST .../learning/files/{file}/retire` under `If-Match` sets `status: retired`,
1479
+ on an active or a pending note; `POST .../learning/files/{file}/approve` under `If-Match` makes a pending note active
1480
+ (see [Approving a note that waits](#approving-a-note-that-waits), below). An edit keeps it waiting: a `PUT` that
1481
+ drops or changes its status is 400 with the rule `status`, so a token holder cannot make a held rule active by
1482
+ writing it back. A note a person creates with `status: pending` waits the same way. A stale
1483
+ ETag, or a name already taken, is 412; neither header (or `If-Match: *`) is 428 `precondition_required`. The note
1484
+ passes the same structural checks as a run's (`checkNote`, in `src/learn/check.ts`), and no grader: a refusal is 400 with
1485
+ `problems`, and nothing is written. A retire is how a person revokes a note, so it checks the note's format alone:
1486
+ its front matter as retired, and the note cap with the status line on top. A secret shape or one of the server's
1487
+ values in its name or text never blocks it (its answer and the log are cut of them as any read is), and a leaking
1488
+ note is replaced by retiring it and creating a clean one. Each write is one commit on `main` in the agent's queue,
1489
+ `learning: <edited, created or retired> by a person: <file>` with a `Changed-By: user` trailer, with `MEMORY.md`
1490
+ rebuilt, `main` moved only from the commit it was made on, and the folder's files brought in line; it answers the
1491
+ note as it now is, with its new `ETag`. `MEMORY.md` itself is never written (400).
1492
+ - `GET /runs/{run_id}/learning`: the run's learning whole (its `used` and `learned` as on its read, its seed, its merge, the grader's verdict with its item for
1493
+ each new note, `{file, keep, question, why}`, `question` the rubric's question a dropped note failed, the checker's
1494
+ problems, what the grade cost), `null` for a run that does not learn; `verdict` is `null` until a grade ran.
1495
+ `GET /runs/{run_id}/learning/diff`: a merged run's merge commit against its parent, else its proposal against its
1496
+ seed, each file's patch as git writes it from the first `@@`, or `withheld` (`too_large`, `secret`).
1497
+
1498
+ Every read is git plumbing at one commit, with no optional lock, and every text it answers is cut of the server's
1499
+ secrets as they are then; a file name holding one (a note named after a value made secret since, say) reads
1500
+ `[redacted]` whole, in the notes (`file`, `superseded_by`), the log's `files` and a diff's `path`, and a write's
1501
+ `Location` leaves it out, while its route still answers the real name to a caller who knows it. A commit's notes are
1502
+ parsed once and kept, for the few commits last read, so the view and every page at that commit read no note again; a
1503
+ log page reads only its own commits (`git log` from the cursor's offset, at most `limit`), and the log's `total` is
1504
+ counted once a commit. A symbolic link at the agent's home, its learning folder or the folder's `.git` is never
1505
+ followed: a read or a write there answers `500`, and nothing is written.
1506
+
1507
+ ### Approving a note that waits
1508
+
1509
+ Who can approve: the owner, signed in with their password. No token approves, the server's own included, so a run that reaches this server only through its API (its MCP tools, a sandbox run) can't approve its own notes. Runs that use bash on the host run as you: they can read this server's files, its session key among them, so no route keeps them from approving. For untrusted tasks, use the sandbox.
1510
+
1511
+ `POST .../learning/files/{file}/approve` takes the console's password session, sent from this server's own origin with
1512
+ a JSON body as every page write is. Any token is 403: the server's own (what scripts and the MCP endpoint's tools
1513
+ carry), a run's door token, and a token sent beside the session. So is every request on a server with accounts off
1514
+ (`AGENTRUN_ACCOUNTS=0`), whose page cookie any token holder can mint. With no credential it is 401, as every route.
1515
+ `capabilities.learning.approve` is true only for the owner's session; every other caller reads `approve: false` with
1516
+ `approve_needs: "password"`. A note that is not pending is 400; a stale ETag is 412, none 428. The approval is one host
1517
+ commit, `learning: approved by a person: <file>`, with the trailers `Changed-By: user` and `Approved-Via: console`; the
1518
+ log shows `by: {user: true, via: "console"}` at the commit's time, never the note's text.
1519
+
1520
+ ## Spend cap
1521
+
1522
+ An agentic run may name `max_cost_usd` (a workflow run may not: `422`). The cap is checked in the run's own process
1523
+ before each model request, the agent's and a compaction's alike, on every harness: what the run has spent so far, plus
1524
+ the worst case of each request still in flight, plus this request's worst case must stay within it, or the request is
1525
+ not sent and the run ends `failed` with `spend_cap_reached`. A request's worst case is its input bound at the higher of
1526
+ the model's input and cache-write prices (the provider may bill any of the input as a cache write), plus the output it is
1527
+ sent with at the output price, plus any fee its tokens do not show (below). Under a cap each request is limited to the
1528
+ output tokens what is left of the cap can buy, thinking included, never more than it asks for or than the model's
1529
+ ceiling (its max output tokens, else its context window, clamped to what the window leaves): on pi through the request's
1530
+ own options (its max tokens, and on Anthropic's API its thinking budget), on claude-agent and codex written into its body
1531
+ by the model proxy (`max_tokens` and `thinking.budget_tokens`, or `max_output_tokens`). The limit is what it is held at,
1532
+ so the cap stays exact. A request is refused only when what is left cannot buy its least: 1,024
1533
+ tokens for its answer (what it asks for, when that is fewer), and when it thinks, the provider's least thinking budget
1534
+ where thinking takes one (Anthropic's, 1,024, the budget squeezed to it at the least) or else its thinking level's
1535
+ budget, since its reasoning then shares the limit (minimal 1,024, low 2,048, medium 8,192, high 16,384). The input bound is one token per UTF-8 byte of what is sent (a byte-level tokenizer never makes
1536
+ a token of less than one byte, and an image's base64 is far more bytes than its tokens), plus what the provider adds
1537
+ server-side (a tool-use prompt, each image), from the same table the model proxy of claude-agent and codex uses; there
1538
+ the proxy measures each request's body. A request in flight holds its worst case until it answers, so requests sent side
1539
+ by side cannot pass the cap together. Spent so far is read from the run's store each time its process starts, so it
1540
+ survives a restart, plus each response since, and with them each charge a paid tool booked (`monid.run`, which is itself
1541
+ refused once the spend reaches the cap; see [monid](#tools)).
1542
+
1543
+ Under a cap, whatever cannot be priced is refused, never passed as $0:
1544
+
1545
+ - A model serve has no price for (a gateway id pi-ai's catalog does not know, with no `AGENT_MODEL_PRICE`): its first
1546
+ request is refused before anything is sent, and the run ends `spend_cap_reached` at $0. With no cap its run's cost
1547
+ reads `null`. A model the catalog lists at $0 is a known $0, and passes any cap.
1548
+ - A model whose output is priced and that names no output ceiling (no max output tokens and no context window): nothing
1549
+ bounds a request. One whose output costs nothing at every price tier keeps a known worst case, and passes.
1550
+ - An input that could not be measured.
1551
+ - A spend no one knows: a cost that is not a number, a cost still pending, and on pi a request a stop or a crash cut
1552
+ with no held figure (below). Every later request of the run is refused. `claude-agent` and `codex` runs also continue
1553
+ after a cut, at the worst case the cap held, as pi does.
1554
+
1555
+ A request you stop counts what it streamed plus up to 1,024 output tokens the provider may have produced after the last
1556
+ word we read; never more than it was held. That is its input bound and each byte it streamed (text, thinking and tool
1557
+ calls on pi; the response as it was sent on `claude-agent` and `codex`) as a token, plus 1,024 tokens of output
1558
+ (`STOP_ALLOWANCE_TOKENS`), at the model's price, and at most the worst case the cap held for it. The cut stream's own
1559
+ usage is never read: it is not what the provider billed (the Responses API reports none until the end, and Anthropic's
1560
+ output count comes at the end). The 1,024 tokens are a stated bound, as the native search allowance is: a provider that
1561
+ went on producing for longer after the stop could bill past what is counted. A request that ended on an error after its
1562
+ response began (an overload part way, a reset), or a summary that failed, still counts at its worst case, and so does a
1563
+ request cut by a crash (its process gone mid-request).
1564
+
1565
+ On pi the figure is written on the request's start mark (`agentrun.request_started`, its worst case) and on the end mark
1566
+ of one stopped (`agentrun.request_ended`, what it counts at), as `heldUsd`; on `claude-agent` and `codex` on the
1567
+ request's `runner.request` record (its worst case) and, for one stopped, on its `runner.turn`. A later process counts it
1568
+ the same: a capped run stopped and sent another message, or opened again after its process died, goes on while its cap
1569
+ allows. A cut request from a store written before serve kept the figure has none, and is a spend no one knows.
1570
+
1571
+ A refusal says so in plain words, with the numbers, on the run's error and on its timeline row: "Not sent: this run's
1572
+ cap of $0.01 can't cover one Claude Sonnet 5.5 request (at least $0.03). Raise the cap to at least $0.03 to run it.", and
1573
+ once a run has spent: "Not sent: the run has spent $0.45 of its $0.50 cap, and its next Claude Sonnet 5.5 request needs at
1574
+ least $0.03. Raise the cap to at least $0.48 to run it." The cap that would run it is what was spent, what requests still
1575
+ answering hold, and the request's least, rounded up to the cent so that it is enough; the model is named as its catalog
1576
+ names it, without a vendor's prefix. The error's code is `spend_cap_reached (out of budget): ` before those words: pi-ai's
1577
+ retry reads only an error's text, and takes "out of budget" as final whatever digits the words hold. A request the cap
1578
+ refused was never sent: the run's usage counts no request for it, and a run whose only request was refused says "no model
1579
+ request sent". A reply the limit cut short says so on the run's timeline: "The reply stopped at 1,500 tokens: all that
1580
+ the $0.15 left of the run's $0.50 cap could buy."
1581
+
1582
+ A request carrying a native web search tool reads pages into its input that its body does not hold (the provider bills
1583
+ them as input): under a cap its input bound is its body's plus an allowance. Claude's own search, an explicit `native`
1584
+ pick, does not run under a cap: each search has a per-use fee the cap cannot reserve yet, so a capped claude-agent run
1585
+ picking it is refused, and on `auto` it searches through Parallel on the server's key (a paid call the cap holds) or else
1586
+ keyless Exa, as a capped codex run does; pi's own search request is held at its context
1587
+ plus 125,000 (5 searches) and its most fee, 5 searches at $0.01. What the request
1588
+ cost, booked once it answers, stops the next request through the cap, and a run whose booked spend passes its cap shows
1589
+ one timeline row saying by how much (`Spent $X, $Y over the run's cap of $Z`).
1590
+
1591
+ The server also checks the run's cost after each response, as a backstop, and stops a run whose cost passed its cap.
1592
+ Either way the run keeps the answer it paid for: a run the cap stopped has `result: {output: null, final_answer}`, the
1593
+ newest answer it received, beside its `error`; one stopped before any answer has `result: null`.
1594
+
1595
+ A run's `cost.usd` is $0 before its first model request (a run cancelled before one included), and `null` when a
1596
+ response reported no price or a request was cut before its end (a stop, a cancel, a crash): no request costs nothing,
1597
+ but a request of unknown price is unknown, never $0. A stopped request shows `null` whether or not its cap counted it at
1598
+ its held worst case.
1599
+
1600
+ ## The faux model
1601
+
1602
+ `--faux MODULE` loads `MODULE` in each run's process. Its default export is called for every model request with the
1603
+ transcript (`context.messages`, pi's messages) and helpers, and returns pi's assistant message:
1604
+
1605
+ ```js
1606
+ export default function reply(context, faux) {
1607
+ const asked = context.messages.filter((m) => m.role === "user").length;
1608
+ if (asked === 1) return faux.message(faux.toolCall("ask_person", { question: "Which region?" }), { stopReason: "toolUse" });
1609
+ return faux.message([faux.thinking("They answered."), faux.text("Using that region.")]);
1610
+ }
1611
+ ```
1612
+
1613
+ `startServe({ faux, fauxBrowser, fauxWeb })` (the tests', not the CLI's) also names modules whose default exports give
1614
+ the `browser` tool's `{ provider, driver }` in place of Browserbase's (pi-browser's fake backend,
1615
+ `test/fixtures/faux-browser.mjs`), `web_fetch`'s direct fetch's `{ lookup, fetchImpl }` in place of the system's resolver and
1616
+ undici (a table of names and pages, `test/fixtures/faux-web.mjs`), and, as `fauxMonid`, the fetch the monid tools send
1617
+ through in place of monid's API (`test/fixtures/faux-monid.mjs`). Each is honored only with `faux`.
1618
+
1619
+ `faux.message`, `faux.text`, `faux.thinking` and `faux.toolCall` are pi-ai's faux helpers; `faux.signal` is aborted when
1620
+ the turn is stopped. A workflow's model node offers the `submit` tool (in its system message's `toolsAdded`), and
1621
+ delivers its record by calling it. A module may also export `cost` (`{input, output, cacheRead, cacheWrite}` in USD per
1622
+ million tokens) to price the faux usage; unpriced, every run's estimate is $0, and with `cost = "unknown"` its usage
1623
+ carries no cost at all, as from a provider that does not price the model. The tests' module is
1624
+ `test/fixtures/faux-model.mjs`.
1625
+
1626
+ ## Safety
1627
+
1628
+ - An import (`agentrun-serve import`, and setup's import) cuts secrets out of everything it writes: the values of the
1629
+ environment's key-shaped variables and the keys saved on this server, the secrets this server made and keeps (its API
1630
+ token, its door token, its sign-in secret, and its webhook's signing secret when the seal key opens it; when it does
1631
+ not, the CLI's import says so once, on stderr, and goes on), and the keys [secretlint](https://github.com/secretlint/secretlint)'s
1632
+ recommended rules find in what it reads (Anthropic, OpenAI, GitHub, Slack and Stripe keys, AWS secret keys beside their
1633
+ name, private keys, database URLs with a password, and more). Each becomes `[redacted]`, and the import says how many
1634
+ distinct values it removed. Known key formats are removed. Other secrets in your session history, like passwords in
1635
+ config files, are imported as they are. So are a key-shaped value this server did not make (a `whsec_` secret from
1636
+ another service) and a run's own door token.
1637
+ - The decision keys (`TYPESAFE_API_KEY`, `PARALLEL_API_KEY`, `OPENROUTER_API_KEY` as Jev's or OpenRouter's) are never in
1638
+ a run's environment or files: a run's process gets on a pipe of their own only those it needs, for its decision
1639
+ providers ([decision workflows](#decision-workflows)) and its web tools: Jev's (by its route) for a node that names Jev
1640
+ or none, Parallel's for a node that names Parallel or for a `web_fetch` or `web_search` that resolves to Parallel
1641
+ ([search and fetch](#search-and-fetch)), OpenRouter's for a node that names OpenRouter. A run that needs none gets no
1642
+ pipe.
1643
+ - `web_fetch`'s direct fetch dials public addresses only, each hop checked and pinned (see [Tools](#tools)): a run cannot reach this
1644
+ machine, its network or a cloud's metadata address through it.
1645
+ - A `browser` session runs at Browserbase, not on this machine: a page the model opens is reached from Browserbase's
1646
+ network, so what the model may reach there is the operator's choice of keys and project. Its downloads and uploads stay
1647
+ in the run's `work/`.
1648
+ - It binds 127.0.0.1 by default, and there refuses a request whose `Host` is not a loopback name (DNS rebinding). On
1649
+ another address (`--listen`, the container's `0.0.0.0`) it serves every `Host` name, and the token is its only lock.
1650
+ It sends no CORS headers, so a page on another origin cannot read an answer.
1651
+ - Every route but `GET /capabilities` needs `Authorization: Bearer <the token>`, compared in constant time, or the
1652
+ browser's cookie under the rules of [the console](#the-console). The console's own files (its HTML, scripts, styles
1653
+ and fonts) hold no data; everything it shows comes through those routes. It loads nothing from the network, and its
1654
+ CSP allows this origin only.
1655
+ - Each run's door listens on loopback and takes only that run's own door token (`DIR/runs/<id>/door-token`, 0600, made
1656
+ at its first launch); a run's process an older server started keeps the server-wide one (`DIR/.door-token`).
1657
+ - A run's process gets the server's environment (the `AGENT_MODEL` variables among it) without the server's token or any
1658
+ key: no `AGENTRUN_TOKEN`, no `AGENTRUN_API_KEY`, no variable whose value is the token, and no variable named like a key
1659
+ (one of its `_`-separated segments, in any case, is `KEY`, `TOKEN`, `SECRET`, `PASSWORD`, `PASSWD`, `PASS`, `PAT`,
1660
+ `CREDENTIAL`, `CREDENTIALS` or `DSN`, or its last is `PWD` after another: `SERVICE_KEY`, `GITHUB_TOKEN_RO`, `DB_PASS`,
1661
+ `SENTRY_DSN`, `DB_PWD`; never `PWD` or `OLDPWD`), whether the launcher's list names it or not. The rule is
1662
+ pi-durable-disk's (`@parcha/pi-durable-disk/secret-name`), which an import's cut and a harness's log take too. The keys it
1663
+ needs come over its pipe. It gets none of the boxes' keys ([Boxes](#boxes)). A tool key reaches it only when its
1664
+ revision names a tool the key unlocks (`MONID_API_KEY` a monid tool, `BROWSERBASE_API_KEY` `browser`; a workflow's
1665
+ tools are those its model and call nodes name), and a model key only when its model needs it ([Models](#models)), read
1666
+ from the revision at each launch, a relaunch or a resume after a restart included.
1667
+ - A variable named like a key that is not on the launcher's list (`capabilities.secrets.names`) is left out of every
1668
+ run's environment, but the launcher does not take it out of the server's: it stays in the server's own environment
1669
+ (`/proc/<pid>/environ`), which any process of the same user can read. Set only the keys the server needs where it
1670
+ starts.
1671
+ - A credential a provider's SDK finds through a variable named like a key is not supported for runs: no run's
1672
+ environment holds the variable, and the SDK reads it from there alone. For Amazon Bedrock that is a web identity token
1673
+ file (`AWS_WEB_IDENTITY_TOKEN_FILE`) and a container role (`AWS_CONTAINER_CREDENTIALS_RELATIVE_URI`,
1674
+ `AWS_CONTAINER_CREDENTIALS_FULL_URI`, `AWS_CONTAINER_AUTHORIZATION_TOKEN` or its `_FILE`); for Vertex,
1675
+ `GOOGLE_APPLICATION_CREDENTIALS`; for Anthropic's workload federation, `ANTHROPIC_IDENTITY_TOKEN_FILE`. Bedrock's access
1676
+ keys or bearer token (held, and handed to a run on Bedrock), an `AWS_PROFILE`, `GOOGLE_CLOUD_API_KEY` or the default
1677
+ application credentials file work. A credential file a provider reads by path (`AWS_PROFILE`'s `~/.aws` files, the
1678
+ default application credentials) is the host's: a run's process reads it for its model, and its file tools cannot.
1679
+ - `TYPESAFE_API_KEY` is a decision key, handed to a workflow run's decision providers on a pipe of their own and never
1680
+ with a run's other secrets, so a pi run on a `typesafe/` model does not get it: its process finds no key for that
1681
+ model, and the run fails.
1682
+ - A run's file tools (`read`, `write`, `edit`) reach its own `work/`, and two places of its own beside it: `read` also
1683
+ reaches the run's `tmp/` (next to `work/`, where a command's spilled output would go), and a write may also land in a
1684
+ temporary directory the run's environment made for a tool (`createTempDir`). Every other path, a link inside `work/`
1685
+ included, is resolved and refused (`outside the workspace`), so a run reads neither the server's token, the door
1686
+ token, `store.sqlite`, another run's files (its `work/` or its `tmp/`) nor `/proc`, and writes nowhere else. This is
1687
+ pi-durable-disk's confinement inside the run's process, not an operating-system boundary: the run and the server
1688
+ share a user (one uid in the container), so the confinement holds only because the run has no shell on this machine.
1689
+ - No path offers a shell on this machine. On the runner `bash` is not bound: a definition that names it is not saved
1690
+ here (`422`), one saved before that check is not runnable (`409`), and a model that calls it anyway, as an agent or as
1691
+ a workflow's model node, is answered that the tool is not available and runs nothing. In a [sandbox](#sandbox) it runs
1692
+ in the run's box, which binds the run's `work/` alone, has no network, and holds no key or token.
1693
+ - Files are served from a run's `work/` and an agent's home only. A path with an empty, `.` or `..` segment, a
1694
+ backslash or a NUL is `400 invalid_file_path`; a segment that starts with `.` (the run's skills under `.agents/`) is
1695
+ `403 system_file_forbidden`; a symlink on the way is `404` (a write or a delete in a home through one, `403`). Every
1696
+ answer is `nosniff`, and HTML carries a CSP with `sandbox` and `default-src 'none'`.
1697
+ - The launcher hands the server every secret on its list that is set over one pipe, which holds 4,096 bytes for sure
1698
+ before the server reads it: each set secret costs its name, its value and two bytes. Past that it refuses to start,
1699
+ saying `the secrets come to N bytes, more than the 4096 a pipe is sure to hold`, and starts nothing. A long value adds up
1700
+ fast (an AWS session token is often over 1,000 bytes): set only the keys the server needs where it starts.
1701
+
1702
+ ### Known gaps
1703
+
1704
+ - The provider keys are checked against pi-ai when this package is tested, not derived when the server starts: the
1705
+ launcher's list and `PROVIDER_KEYS` match the pi-ai this package is tested with (its peer range is `*`, as Pi's
1706
+ package guidance asks). The drift test fails, naming the provider and the key, on a pi-ai that reads a key neither
1707
+ names. A pi-ai installed past that test that reads a key neither
1708
+ names would leave it in the server's environment and out of every run's, and a run on that provider would fail at
1709
+ its start for want of the key.
1710
+ - The cut is by name alone. A variable named like no key whose value is one reaches a run's environment and is not cut
1711
+ from what an import or a harness's log keeps: a URL with a user and password in it (`DATABASE_URL`, `HTTPS_PROXY`),
1712
+ headers that carry a token (`OTEL_EXPORTER_OTLP_HEADERS`), or a held key's
1713
+ value under another name.
1714
+ - The 4,096-byte pipe limit stays until the launcher writes the pipe from a background subshell that blocks until the
1715
+ server has read it.
1716
+
1717
+ ## Test
1718
+
1719
+ ```sh
1720
+ npm run build -w @parcha/agentrun-dsl -w @parcha/agentrun-pi -w @parcha/pi-durable-disk -w @parcha/pi-durable-agent -w @parcha/agentrun-serve
1721
+ npm test -w @parcha/agentrun-serve
1722
+ ```
1723
+
1724
+ The tests start real run processes on the faux model, both kinds: no key, no network.