@foldrun/core 16.0.0 → 17.0.0

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.
@@ -66,6 +66,12 @@ export interface EgressGrant {
66
66
  identities?: Record<string, {
67
67
  audience: string;
68
68
  }>;
69
+ /** The proxy's search door is open for this step (search-egress.ts
70
+ * searchDoorWanted): a held step's way to the account's search engine.
71
+ * `max` caps how many searches go through it. Absent: the door refuses. */
72
+ search?: {
73
+ max?: number;
74
+ };
69
75
  }
70
76
  export interface EgressLease {
71
77
  /** The base the pod sends through: `http://…/e/<token>`. */
@@ -77,6 +83,9 @@ export interface EgressLease {
77
83
  /** The PEM of the CA the forward door signs with for a host a secret is
78
84
  * bound to, so the sandbox can trust exactly those interceptions. */
79
85
  ca?: string;
86
+ /** The proxy's search door for this lease (`…/s/<token>`), when the
87
+ * proxy has one: where a held step's web search is sent. */
88
+ search?: string;
80
89
  /** Whether a site off the step's list is refused (true) or only named
81
90
  * in the trace (false). */
82
91
  enforce?: boolean;
@@ -162,6 +162,14 @@ export interface PlatformHooks {
162
162
  * trace as not enforced.
163
163
  */
164
164
  confinesBrowsing?(isolation: string): boolean;
165
+ /**
166
+ * Does this isolation mode wall a step whose `network:` is restricted and
167
+ * enforced to the egress proxy alone (a `filtered` pod)? True: such a
168
+ * step's web search goes through the proxy's search door (FOL-128,
169
+ * search-egress.ts), since the account's search engine is out of its
170
+ * reach. Absent or false: it reaches the engine as it always did.
171
+ */
172
+ wallsRestricted?(isolation: string): boolean;
165
173
  /**
166
174
  * An operator setting, by the environment variable that used to hold it
167
175
  * (30 Oct 2026): the platform answers with the operator's value where one
@@ -418,7 +418,39 @@ export declare const RETRY_SH = "retry() { what=$1; shift; n=1; until \"$@\"; do
418
418
  * 23 Oct 2026: Node 22.23.4 (the 21 Oct security release: Brotli decoder
419
419
  * RCE, TLS hostname bypasses); the pin before carried 22.23.3. */
420
420
  export declare const NODE_BASE = "node:22-trixie-slim@sha256:8eb619e402eaede1748a3c8173bffab391592812e85136452f781741c7242ddf";
421
- export declare const DOCKERFILE = "FROM node:22-trixie-slim@sha256:8eb619e402eaede1748a3c8173bffab391592812e85136452f781741c7242ddf AS base\nRUN apt-get update \\\n && apt-get install -y --no-install-recommends python3 python3-venv ca-certificates bash util-linux tar openssh-client sshpass git curl \\\n && rm -rf /var/lib/apt/lists/* \\\n && useradd -m -u 10001 agent\n# uv builds the declared python environments (runtime.ts): a fraction of\n# pip's time, and it can fetch a pinned python the image does not carry.\nCOPY --from=ghcr.io/astral-sh/uv:0.11.25 /uv /uvx /usr/local/bin/\nENV PLAYWRIGHT_BROWSERS_PATH=/opt/browser NODE_PATH=/usr/local/lib/node_modules\n\nFROM base AS core\nWORKDIR /opt/runner\nCOPY foldrun-core.tgz ./\nRUN npm init -y >/dev/null && npm install ./foldrun-core.tgz --omit=dev \\\n && npm cache clean --force >/dev/null 2>&1 \\\n && rm -f foldrun-core.tgz node_modules/@foldrun/core/README.md\n\nFROM base AS slim\n# Fonts, because a step that draws text without a browser still needs them:\n# the full image gets 51 from Playwright's --with-deps, slim had none, so from\n# 2026-09-29 (when non-browsing steps moved to slim) every resvg/sharp diagram\n# rendered its labels as empty boxes \u2014 expert-witness-desk's validator failed\n# four passes on a post image that was \"three empty boxes\". DejaVu covers\n# Latin, Greek and Cyrillic in a few MB; fontconfig is how renderers find it.\n# DejaVu alone still drew emoji, Chinese, Japanese, Korean, Devanagari and\n# Thai as empty boxes (reproduced 2026-10-01 with resvg-js 2.6 and sharp\n# 0.34), so four more, the smallest set that drew all of them \u2014 8 MB:\n# Symbola emoji and symbols, as outlines. NOT Noto Color Emoji (10 MB):\n# resvg draws nothing from its bitmap glyphs, so a resvg\n# diagram kept its empty boxes.\n# WenQuanYi Micro Hei Chinese, Japanese kana and Korean Hangul, one file.\n# Lohit Devanagari, Loma Hindi and Thai.\n# Here, not in base, so the full image's browser layers stay cached.\nRUN apt-get update \\\n && apt-get install -y --no-install-recommends fonts-dejavu-core fontconfig fonts-symbola fonts-wqy-microhei fonts-lohit-deva fonts-tlwg-loma-otf \\\n && rm -rf /var/lib/apt/lists/* \\\n && fc-cache -f >/dev/null\n# The Playwright client only, the same pinned version as the browser pod's\n# server (the wire protocol is version-locked), so a tool that imports it\n# still loads; there is nothing here for it to launch.\n# npm's download cache is dropped in the same layer: it was 190 MB of every\n# image, read by nothing after the build.\nRUN npm install -g playwright@1.63.0 axe-core@4.13.0 >/dev/null && npm cache clean --force >/dev/null 2>&1\nWORKDIR /opt/runner\nCOPY --from=core --chown=agent:agent /opt/runner/ ./\nCOPY --chown=agent:agent driver.mjs entry.sh ./\nRUN mkdir -p /workspace /library /opt/runner/job /home/agent/.foldrun/runner/.runtimes /opt/foldrun-runtimes/shared/.runtimes \\\n && chown agent:agent /opt/runner \\\n && chown -R agent:agent /workspace /library /opt/runner/job /home/agent/.foldrun /opt/foldrun-runtimes \\\n && chmod +x /opt/runner/entry.sh\nENTRYPOINT [\"/opt/runner/entry.sh\"]\n\nFROM base AS browsers\n# Real browsers, because directories and portals increasingly render with\n# JavaScript and a plain fetch sees only the empty shell. Chromium is the one the\n# browser tool drives by default; Firefox and WebKit (Safari's engine) are\n# there for an agent asked to see a page the way those render it. Installed\n# to a fixed path the agent user can read (the default cache would be\n# root's HOME). The browsers' own sandboxes are disabled at launch time \u2014 in\n# this platform the container/gVisor IS the sandbox, and the two fight.\n# Pinned exactly, not @1: web browse's numbered elements use ariaSnapshot's\n# \"ai\" mode (1.59+), and the per-account browser pod runs this same image, so\n# a floating version would move both under a working tool on any rebuild.\n# Raise it on purpose, with the gallery tests and one real call.\n# axe-core beside it is web browse's mode=a11y: one file the tool injects\n# into the page; without it the mode falls back to its own shorter checks.\n# Xvfb by name: the browser pod starts it at boot and web browse starts one\n# per call for headless: false. It used to arrive only as one of Playwright's\n# --with-deps packages, so a Playwright bump that dropped it would have\n# broken every windowed browser without a word. No xauth: nothing here runs\n# xvfb-run, and Xvfb started without -auth takes the local client as it is.\nRUN apt-get update \\\n && apt-get install -y --no-install-recommends xvfb \\\n && rm -rf /var/lib/apt/lists/*\n# Google Chrome and Chrome beta come from Google's apt repository, which\n# Playwright adds; each is tried ENGINE_DOWNLOAD_ATTEMPTS times. Only on\n# x86_64: Google ships no Linux Chrome for arm64, so there it is not tried.\nRUN npm install -g playwright@1.63.0 axe-core@4.13.0 >/dev/null \\\n && playwright install --with-deps chromium firefox webkit >/dev/null \\\n && retry() { what=$1; shift; n=1; until \"$@\"; do if [ \"$n\" -ge 3 ]; then echo \"runner image: $what - download failed $n times, giving up\" >&2; return 1; fi; echo \"runner image: $what - download failed (attempt $n of 3), retrying in $((n * 15))s\" >&2; sleep $((n * 15)); n=$((n + 1)); done; } \\\n && if [ \"$(uname -m)\" = x86_64 ]; then \\\n retry chrome playwright install --with-deps chrome >/dev/null || echo \"runner image: chrome not installed - engine: chrome would fall back to chromium\" >&2; \\\n retry chrome-beta playwright install --with-deps chrome-beta >/dev/null || echo \"runner image: chrome-beta not installed\" >&2; \\\n else echo \"runner image: no Google Chrome for $(uname -m) - engine: chrome falls back to chromium\"; fi \\\n && chmod -R a+rX /opt/browser \\\n && npm cache clean --force >/dev/null 2>&1\n# Lightpanda (engine: lightpanda): a browser that runs the JavaScript and\n# never draws \u2014 a fraction of Chromium's memory for reading and filling\n# pages. Its own program, which web browse starts beside a call and drives\n# over the DevTools protocol; shipped unmodified (AGPL-3.0). Pinned by\n# checksum (GitHub's own asset digests, checked again here). 0.4.1 since the\n# move to Debian 13: 0.3.7 on wants glibc 2.38, and Debian 12's 2.36 held it\n# at 0.3.6. An arch without a build leaves the engine out, and the tool says\n# so when asked for it. Each download (with its checksum) is tried\n# ENGINE_DOWNLOAD_ATTEMPTS times before the engine is left out.\n# Raise it on purpose: the new release's two sha256s, then one\n# engine=lightpanda call on each arch.\nRUN arch=$(uname -m) \\\n && case \"$arch\" in \\\n x86_64) sum=1d40801e72c0bc61b2cbd3f3562bcfc46de7b79e0568f33f686b64f2e587610a ;; \\\n aarch64) sum=664775c7f5ab69cc3189954c7f9345e25c167cb4dace016173e629f9a5e82c42 ;; \\\n *) sum= ;; \\\n esac \\\n && mkdir -p /opt/browser/lightpanda \\\n && retry() { what=$1; shift; n=1; until \"$@\"; do if [ \"$n\" -ge 3 ]; then echo \"runner image: $what - download failed $n times, giving up\" >&2; return 1; fi; echo \"runner image: $what - download failed (attempt $n of 3), retrying in $((n * 15))s\" >&2; sleep $((n * 15)); n=$((n + 1)); done; } \\\n && fetch() { curl -fsSL -o /opt/browser/lightpanda/lightpanda \"https://github.com/lightpanda-io/browser/releases/download/0.4.1/lightpanda-$arch-linux\" \\\n && echo \"$sum /opt/browser/lightpanda/lightpanda\" | sha256sum -c - >/dev/null; } \\\n && if [ -n \"$sum\" ] && retry lightpanda fetch; then \\\n chmod a+rx /opt/browser/lightpanda/lightpanda && /opt/browser/lightpanda/lightpanda version; \\\n else rm -f /opt/browser/lightpanda/lightpanda; echo \"runner image: lightpanda not installed for $arch - engine: lightpanda says so when asked\" >&2; fi\n# Obscura (engine: obscura): a headless browser in Rust around V8 that does\n# draw \u2014 screenshots, a raster PDF, a screencast \u2014 light like Lightpanda.\n# Apache-2.0. The plain build, not -stealth: this platform does not help a\n# page not see automation. Two binaries, obscura and obscura-worker, which\n# must sit side by side. Pinned by checksum; glibc 2.35 is its floor, so\n# Debian 13 (2.41) runs it. As above, a download is tried\n# ENGINE_DOWNLOAD_ATTEMPTS times, then a failed one leaves the engine out.\nRUN arch=$(uname -m) \\\n && case \"$arch\" in \\\n x86_64) sum=1534d1e6ddaf3d080ec4091eb41d0a4d8cc042a48b607d3c410fc13b482a9eec ;; \\\n aarch64) sum=5ecf980bca3060236a7a86ec7ed83d943e6598ee87caa46d20325d90bc75f979 ;; \\\n *) sum= ;; \\\n esac \\\n && mkdir -p /opt/browser/obscura \\\n && retry() { what=$1; shift; n=1; until \"$@\"; do if [ \"$n\" -ge 3 ]; then echo \"runner image: $what - download failed $n times, giving up\" >&2; return 1; fi; echo \"runner image: $what - download failed (attempt $n of 3), retrying in $((n * 15))s\" >&2; sleep $((n * 15)); n=$((n + 1)); done; } \\\n && fetch() { curl -fsSL -o /tmp/obscura.tgz \"https://github.com/h4ckf0r0day/obscura/releases/download/v0.2.3/obscura-$arch-linux.tar.gz\" \\\n && echo \"$sum /tmp/obscura.tgz\" | sha256sum -c - >/dev/null; } \\\n && if [ -n \"$sum\" ] && retry obscura fetch \\\n && tar -xzf /tmp/obscura.tgz -C /opt/browser/obscura obscura obscura-worker; then \\\n chmod a+rx /opt/browser/obscura/obscura /opt/browser/obscura/obscura-worker && /opt/browser/obscura/obscura --version; \\\n else rm -rf /opt/browser/obscura/*; echo \"runner image: obscura not installed for $arch - engine: obscura says so when asked\" >&2; fi \\\n && rm -f /tmp/obscura.tgz\n# What this image actually has, written down: /opt/browser/engines.json, one\n# entry per engine (its path and version, or null when the install above\n# left it out) plus Xvfb. Chromium's version is its own --version (dotted,\n# so FOLDRUN_RUNNER_ENGINES carries it: a pinned user_agent on engine\n# chromium is compared with it, not with Google Chrome's) then the build.\n# web browse reads it for its \"built without\" answer, and the deploy reads\n# it to report the engines beside the version.\n# On x86_64 a missing engine FAILS the build: every engine ships for that\n# arch, so a gap there is a failed download, and an image that quietly lacks\n# the Chrome or Lightpanda a desk names would fail those runs instead. A\n# failed build leaves the previous image running and says why. Elsewhere\n# (arm64 has no Google Chrome) the gap is recorded and the image ships.\nRUN node -e ' \\\n const fs = require(\"fs\"), cp = require(\"child_process\"), pw = require(\"playwright\"); \\\n const at = (p) => (p && fs.existsSync(p) ? p : null); \\\n const ver = (bin, args) => { try { return cp.execFileSync(bin, args, { timeout: 30000, stdio: [\"ignore\", \"pipe\", \"ignore\"] }).toString().trim().split(\"\\n\")[0] || null; } catch { return null; } }; \\\n const one = (p, v) => (p ? { path: p, version: v } : null); \\\n const pwBuild = (p) => (p ? (p.match(/(chromium|firefox|webkit)-(\\d+)/) || [])[0] || null : null); \\\n const lp = at(\"/opt/browser/lightpanda/lightpanda\"); \\\n const cr = at(pw.chromium.executablePath()); \\\n const ob = at(\"/opt/browser/obscura/obscura-worker\") && at(\"/opt/browser/obscura/obscura\"); \\\n const engines = { \\\n chromium: one(cr, cr && [ver(cr, [\"--version\"]), pwBuild(cr)].filter(Boolean).join(\" \")), \\\n chrome: one(at(\"/opt/google/chrome/chrome\"), ver(\"/opt/google/chrome/chrome\", [\"--version\"])), \\\n \"chrome-beta\": one(at(\"/opt/google/chrome-beta/chrome\"), ver(\"/opt/google/chrome-beta/chrome\", [\"--version\"])), \\\n firefox: one(at(pw.firefox.executablePath()), pwBuild(pw.firefox.executablePath())), \\\n webkit: one(at(pw.webkit.executablePath()), pwBuild(pw.webkit.executablePath())), \\\n lightpanda: one(lp, lp && ver(lp, [\"version\"])), \\\n obscura: one(ob, ob && ver(ob, [\"--version\"])), \\\n }; \\\n const xvfb = ver(\"sh\", [\"-c\", \"command -v Xvfb\"]); \\\n const arch = cp.execFileSync(\"uname\", [\"-m\"]).toString().trim(); \\\n const manifest = { arch, playwright: require(\"playwright/package.json\").version, engines, xvfb }; \\\n fs.writeFileSync(\"/opt/browser/engines.json\", JSON.stringify(manifest, null, 2) + \"\\n\"); \\\n console.log(JSON.stringify(manifest)); \\\n const missing = [\"chromium\", \"chrome\", \"firefox\", \"webkit\", \"lightpanda\", \"obscura\"].filter((e) => !engines[e]).concat(xvfb ? [] : [\"Xvfb\"]); \\\n if (missing.length && arch === \"x86_64\") { \\\n console.error(\"runner image: MISSING ENGINES on x86_64: \" + missing.join(\", \")); \\\n console.error(\"runner image: every engine ships for x86_64, so a missing one is a failed download (the retry lines above say which) - failing the build\"); \\\n process.exit(1); \\\n } \\\n if (missing.length) console.error(\"runner image: built without \" + missing.join(\", \") + \" on \" + arch); \\\n ' \\\n && chmod a+r /opt/browser/engines.json\n\nFROM browsers AS full\nWORKDIR /opt/runner\nCOPY --from=core --chown=agent:agent /opt/runner/ ./\nCOPY --chown=agent:agent driver.mjs entry.sh ./\nRUN mkdir -p /workspace /library /opt/runner/job /home/agent/.foldrun/runner/.runtimes /opt/foldrun-runtimes/shared/.runtimes \\\n && chown agent:agent /opt/runner \\\n && chown -R agent:agent /workspace /library /opt/runner/job /home/agent/.foldrun /opt/foldrun-runtimes \\\n && chmod +x /opt/runner/entry.sh\nENTRYPOINT [\"/opt/runner/entry.sh\"]\n";
421
+ /** Which definition of the OS part this core holds: 16 hex of the sha256 of
422
+ * its text. A base image carries it (label io.foldrun.runner-os and
423
+ * /etc/foldrun-runner-os); a base from another definition is refused. */
424
+ export declare const RUNNER_OS_ID: string;
425
+ /** The runner's OS part on its own — what the base image is built from
426
+ * (targets RUNNER_OS_TARGETS). No build context: it copies nothing local. */
427
+ export declare const RUNNER_OS_DOCKERFILE: string;
428
+ /** The OS part's build target for each runner variant. */
429
+ export declare const RUNNER_OS_TARGETS: {
430
+ readonly slim: "slim-os";
431
+ readonly full: "browsers";
432
+ };
433
+ /** The base images a runner is built FROM, by digest, one per variant. */
434
+ export type RunnerBase = {
435
+ slim: string;
436
+ full: string;
437
+ };
438
+ /**
439
+ * The runner base from FOLDRUN_RUNNER_BASE_SLIM and FOLDRUN_RUNNER_BASE_FULL:
440
+ * both or neither (empty counts as unset, as FOLDRUN_RUNNER_IMAGE does), each
441
+ * an image by digest — a tag would let the same runner tag hold another
442
+ * base's bytes. Anything else throws: a half-set base is a broken deploy,
443
+ * not a reason to quietly build the OS again.
444
+ */
445
+ export declare function runnerBase(env?: NodeJS.ProcessEnv): RunnerBase | null;
446
+ /**
447
+ * The runner's Dockerfile: with no base, the OS part and the app part in one
448
+ * file (a self-contained build); with one, the app part FROM the base's two
449
+ * images. The app part's text is the same either way.
450
+ */
451
+ export declare function runnerDockerfile(base?: RunnerBase | null): string;
452
+ /** The self-contained runner Dockerfile (no base): runnerDockerfile(). */
453
+ export declare const DOCKERFILE: string;
422
454
  /** The docker run container's entrypoint (entry.sh), exported for its tests. */
423
455
  export declare const ENTRY: string;
424
456
  /** Which build target of the runner image (see DOCKERFILE). */
@@ -922,7 +922,7 @@ export const RETRY_SH = `retry() { what=$1; shift; n=1; until "$@"; do if [ "$n"
922
922
  * 23 Oct 2026: Node 22.23.4 (the 21 Oct security release: Brotli decoder
923
923
  * RCE, TLS hostname bypasses); the pin before carried 22.23.3. */
924
924
  export const NODE_BASE = "node:22-trixie-slim@sha256:8eb619e402eaede1748a3c8173bffab391592812e85136452f781741c7242ddf";
925
- // Two images from one file, as build targets.
925
+ // Two images from one file, as build targets, in two parts.
926
926
  //
927
927
  // full (the default, the last stage) — everything, browsers included. The
928
928
  // per-account browser pod runs it, and so does any step that may
@@ -935,10 +935,42 @@ export const NODE_BASE = "node:22-trixie-slim@sha256:8eb619e402eaede1748a3c8173b
935
935
  // (run-k8s.ts picks), and its declared packages arrive at run time
936
936
  // through the runtime cache — uv is in the base for exactly that.
937
937
  //
938
+ // The parts (FOL-50, 5 Nov 2026):
939
+ //
940
+ // the OS RUNNER_OS_DOCKERFILE: Debian, every apt package, uv, the
941
+ // Playwright client and, for full, the browsers (Google's Chrome
942
+ // included). Targets `slim-os` and `browsers`. Everything that
943
+ // writes /var/lib/dpkg/status is here and nowhere else.
944
+ // the app core and the driver on top (CORE_STAGE, CORE_INSTALL): files
945
+ // only, no apt.
946
+ //
947
+ // Built together (runnerDockerfile() — a laptop, a self-hoster, images.yml)
948
+ // it is one image as before. The hosted platform builds the OS part on its
949
+ // own as the runner BASE image, pins it by digest (foldrun-infra
950
+ // images/runner-base.env, refreshed weekly and at once for a fixable critical
951
+ // vulnerability) and builds the app part FROM it (FOLDRUN_RUNNER_BASE_SLIM /
952
+ // _FULL). A release that changes only foldrun's code then keeps the base's
953
+ // bytes, so the dpkg status a `runtime: system:` snapshot was built on is
954
+ // still there after the deploy (runtime.ts systemInstallSh) — rebuilding the
955
+ // OS on every core change moved Chrome, the apt index and every package's
956
+ // status line, and each release cost each package set a full apt install.
957
+ //
938
958
  // The browsers sit BELOW the core install in `full`, as they always have,
939
959
  // so a core change rebuilds one thin layer and not 1.4 GB of Chromium.
940
- export const DOCKERFILE = `FROM ${NODE_BASE} AS base
960
+ /** Stands for the OS definition's id inside its own text: the id is the
961
+ * sha256 of the text with this in place, then substituted in. */
962
+ const OS_ID_SLOT = "@@FOLDRUN_RUNNER_OS@@";
963
+ /** The end of each OS target: which definition built it, as a label and as
964
+ * a file the app part checks (OS_GUARD). Not under /var/lib/dpkg. */
965
+ const OS_MARK = `LABEL io.foldrun.runner-os=${OS_ID_SLOT}
966
+ RUN echo ${OS_ID_SLOT} > /etc/foldrun-runner-os`;
967
+ const OS_TEMPLATE = `FROM ${NODE_BASE} AS base
968
+ # upgrade: node's image lags Debian security (the platform images learnt it
969
+ # on 6 Oct 2026, perl-base), and the hosted runner's base is rebuilt weekly
970
+ # precisely so those fixes arrive; without it a refresh changed nothing the
971
+ # node image already carried.
941
972
  RUN apt-get update \\
973
+ && DEBIAN_FRONTEND=noninteractive apt-get upgrade -y --no-install-recommends \\
942
974
  && apt-get install -y --no-install-recommends python3 python3-venv ca-certificates bash util-linux tar openssh-client sshpass git curl \\
943
975
  && rm -rf /var/lib/apt/lists/* \\
944
976
  && useradd -m -u 10001 agent
@@ -947,8 +979,7 @@ RUN apt-get update \\
947
979
  COPY --from=ghcr.io/astral-sh/uv:${UV_VERSION} /uv /uvx /usr/local/bin/
948
980
  ENV PLAYWRIGHT_BROWSERS_PATH=/opt/browser NODE_PATH=/usr/local/lib/node_modules
949
981
 
950
- ${CORE_STAGE}
951
- FROM base AS slim
982
+ FROM base AS slim-os
952
983
  # Fonts, because a step that draws text without a browser still needs them:
953
984
  # the full image gets 51 from Playwright's --with-deps, slim had none, so from
954
985
  # 2026-09-29 (when non-browsing steps moved to slim) every resvg/sharp diagram
@@ -974,7 +1005,8 @@ RUN apt-get update \\
974
1005
  # npm's download cache is dropped in the same layer: it was 190 MB of every
975
1006
  # image, read by nothing after the build.
976
1007
  RUN npm install -g playwright@1.63.0 axe-core@4.13.0 >/dev/null && npm cache clean --force >/dev/null 2>&1
977
- ${CORE_INSTALL}
1008
+ ${OS_MARK}
1009
+
978
1010
  FROM base AS browsers
979
1011
  # Real browsers, because directories and portals increasingly render with
980
1012
  # JavaScript and a plain fetch sees only the empty shell. Chromium is the one the
@@ -1099,9 +1131,65 @@ RUN node -e ' \\
1099
1131
  if (missing.length) console.error("runner image: built without " + missing.join(", ") + " on " + arch); \\
1100
1132
  ' \\
1101
1133
  && chmod a+r /opt/browser/engines.json
1102
-
1134
+ ${OS_MARK}
1135
+ `;
1136
+ /** Which definition of the OS part this core holds: 16 hex of the sha256 of
1137
+ * its text. A base image carries it (label io.foldrun.runner-os and
1138
+ * /etc/foldrun-runner-os); a base from another definition is refused. */
1139
+ export const RUNNER_OS_ID = crypto.createHash("sha256").update(OS_TEMPLATE).digest("hex").slice(0, 16);
1140
+ /** The runner's OS part on its own — what the base image is built from
1141
+ * (targets RUNNER_OS_TARGETS). No build context: it copies nothing local. */
1142
+ export const RUNNER_OS_DOCKERFILE = OS_TEMPLATE.split(OS_ID_SLOT).join(RUNNER_OS_ID);
1143
+ /** The OS part's build target for each runner variant. */
1144
+ export const RUNNER_OS_TARGETS = { slim: "slim-os", full: "browsers" };
1145
+ /** The app part's first word in both variants: the OS under it is the one
1146
+ * this core's text describes. A base built from an older definition (a
1147
+ * Playwright bump, a new apt package) would otherwise ship a runner whose
1148
+ * browsers or packages are not the ones its core expects. */
1149
+ const OS_GUARD = `RUN test "$(cat /etc/foldrun-runner-os 2>/dev/null)" = "${RUNNER_OS_ID}" \\
1150
+ || { echo "runner image: its base was built from another definition (wants ${RUNNER_OS_ID}, has $(cat /etc/foldrun-runner-os 2>/dev/null || echo none)) - build the base again: bash foldrun-infra/dev/ci/runner-base.sh refresh" >&2; exit 1; }`;
1151
+ const BASE_REF = /^[a-z0-9][a-z0-9._/:-]*@sha256:[0-9a-f]{64}$/;
1152
+ /**
1153
+ * The runner base from FOLDRUN_RUNNER_BASE_SLIM and FOLDRUN_RUNNER_BASE_FULL:
1154
+ * both or neither (empty counts as unset, as FOLDRUN_RUNNER_IMAGE does), each
1155
+ * an image by digest — a tag would let the same runner tag hold another
1156
+ * base's bytes. Anything else throws: a half-set base is a broken deploy,
1157
+ * not a reason to quietly build the OS again.
1158
+ */
1159
+ export function runnerBase(env = process.env) {
1160
+ const slim = env.FOLDRUN_RUNNER_BASE_SLIM ?? "";
1161
+ const full = env.FOLDRUN_RUNNER_BASE_FULL ?? "";
1162
+ if (!slim && !full)
1163
+ return null;
1164
+ if (!slim || !full) {
1165
+ throw new Error("FOLDRUN_RUNNER_BASE_SLIM and FOLDRUN_RUNNER_BASE_FULL go together: set both (the base's two images, by digest) or neither");
1166
+ }
1167
+ for (const [k, v] of [["FOLDRUN_RUNNER_BASE_SLIM", slim], ["FOLDRUN_RUNNER_BASE_FULL", full]]) {
1168
+ if (!BASE_REF.test(v))
1169
+ throw new Error(`${k} must name an image by digest (name@sha256:<64 hex>), not ${JSON.stringify(v.slice(0, 120))}`);
1170
+ }
1171
+ return { slim, full };
1172
+ }
1173
+ /**
1174
+ * The runner's Dockerfile: with no base, the OS part and the app part in one
1175
+ * file (a self-contained build); with one, the app part FROM the base's two
1176
+ * images. The app part's text is the same either way.
1177
+ */
1178
+ export function runnerDockerfile(base = null) {
1179
+ const os = base
1180
+ ? `FROM ${base.slim} AS slim-os\nFROM ${base.full} AS browsers\nFROM slim-os AS base\n`
1181
+ : RUNNER_OS_DOCKERFILE;
1182
+ return `${os}
1183
+ ${CORE_STAGE}
1184
+ FROM slim-os AS slim
1185
+ ${OS_GUARD}
1186
+ ${CORE_INSTALL}
1103
1187
  FROM browsers AS full
1188
+ ${OS_GUARD}
1104
1189
  ${CORE_INSTALL}`;
1190
+ }
1191
+ /** The self-contained runner Dockerfile (no base): runnerDockerfile(). */
1192
+ export const DOCKERFILE = runnerDockerfile();
1105
1193
  // runtime: system: — apt as root, before the drop (runtime.ts systemInstallSh).
1106
1194
  // set -e is off around it: a failed install is reported by the driver, which
1107
1195
  // reads the status file and fails the step with apt's own words.
@@ -1143,7 +1231,9 @@ export function runnerImageTag(variant = "full") {
1143
1231
  // The fingerprint hashes the *built code*, not the version — a version
1144
1232
  // string that nobody bumped would pin every future run to the runner
1145
1233
  // image of whatever core happened to build first.
1146
- const hash = crypto.createHash("sha256").update(DRIVER + "\n" + DOCKERFILE + "\n" + ENTRY);
1234
+ // The Dockerfile as it will be built — with the base's digests in it when
1235
+ // one is set, so a new base is a new tag.
1236
+ const hash = crypto.createHash("sha256").update(DRIVER + "\n" + runnerDockerfile(runnerBase()) + "\n" + ENTRY);
1147
1237
  const dist = path.join(corePackageDir(), "dist");
1148
1238
  if (fs.existsSync(dist)) {
1149
1239
  for (const entry of fs.readdirSync(dist, { recursive: true }).sort()) {
@@ -1189,6 +1279,12 @@ export function ensureRunnerImage(opts = {}) {
1189
1279
  const log = [];
1190
1280
  if (explicit)
1191
1281
  return { tag, log };
1282
+ const base = runnerBase();
1283
+ // A base is one platform's images (the hosted base is linux/amd64): a
1284
+ // cross-build on it would pull the wrong arch or none.
1285
+ if (base && opts.platform) {
1286
+ throw new Error(`a runner base names one platform's images: unset FOLDRUN_RUNNER_BASE_SLIM and FOLDRUN_RUNNER_BASE_FULL to build for ${opts.platform}`);
1287
+ }
1192
1288
  const have = spawnSync(cli(), ["image", "inspect", tag], { stdio: "ignore" });
1193
1289
  if (have.status === 0)
1194
1290
  return { tag, log };
@@ -1203,8 +1299,9 @@ export function ensureRunnerImage(opts = {}) {
1203
1299
  fs.renameSync(path.join(build, tarball), path.join(build, "foldrun-core.tgz"));
1204
1300
  fs.writeFileSync(path.join(build, "driver.mjs"), DRIVER);
1205
1301
  fs.writeFileSync(path.join(build, "entry.sh"), ENTRY);
1206
- fs.writeFileSync(path.join(build, "Dockerfile"), DOCKERFILE);
1207
- log.push(`building runner image ${tag} (first run only)`);
1302
+ // The same text the tag hashed (runnerImageTag), base and all.
1303
+ fs.writeFileSync(path.join(build, "Dockerfile"), runnerDockerfile(base));
1304
+ log.push(`building runner image ${tag} (first run only)${base ? ` on base ${base.full.split("@")[1].slice(7, 19)}` : ""}`);
1208
1305
  const args = [
1209
1306
  "build",
1210
1307
  ...(opts.platform ? ["--platform", opts.platform] : []),
@@ -50,6 +50,7 @@ import { loadCatalog, checkModel, clampEffort, catalogCost, findModel, tokenPric
50
50
  import { resolveSecrets, getSecret, materializeSecrets, secretSites, isClientCertValue, clientCertOf, withoutHeldCerts, isIdentityValue, identityOf } from "./secrets.js";
51
51
  import { resolveNetwork, networkLine, networkEnforceWanted, proxyEnv, siteCovers, EGRESS_CA_ENV } from "./network.js";
52
52
  import { BROWSER_CONFINED_ENV, browseNetworkLine, browseVerdict } from "./browse-egress.js";
53
+ import { SEARCH_DOOR_ENV, searchDoorWanted, searchProvided } from "./search-egress.js";
53
54
  import { materializeFileSecrets, cleanupFileSecrets } from "./secret-files.js";
54
55
  import { buildApiTools, secretsUsedByApi } from "./api-tools.js";
55
56
  import { buildA2ATools } from "./a2a-tools.js";
@@ -2885,6 +2886,29 @@ mayDefer) {
2885
2886
  // A browsing step on an install with the door says whether it is held
2886
2887
  // to its list, and which tier its browser falls in (browse-egress.ts).
2887
2888
  push("info", browse ? browseNetworkLine(network, clockEnv.FOLDRUN_BROWSER_VENDOR, { hosted: browse.kind === "hosted" }) : networkLine(network, forward ? forward.enforce === true : null));
2889
+ // Web search under a held list (FOL-128, search-egress.ts): the
2890
+ // account's engine through the proxy's search door, for the actions
2891
+ // our engine answers — decided here, from this step's own config and
2892
+ // the lease's effective enforce, and carried on the grant, which the
2893
+ // pod cannot write. Only where the executor walls such a step (the
2894
+ // others reach the engine directly). Off a held list: nothing here.
2895
+ const searchDoor = forward && !!isolation && platform.wallsRestricted?.(isolation) === true
2896
+ ? searchDoorWanted({
2897
+ level: network.level,
2898
+ defaults: network.defaults,
2899
+ enforce: forward.enforce === true,
2900
+ web: scriptSpecs.some((sc) => sc.name === "web"),
2901
+ actions: web.actions ?? null,
2902
+ provided: searchProvided(web.raw),
2903
+ limits: stepLimits,
2904
+ })
2905
+ : { door: null };
2906
+ if (searchDoor.door)
2907
+ grant.search = searchDoor.door;
2908
+ else
2909
+ delete grant.search;
2910
+ if (searchDoor.line)
2911
+ push("info", searchDoor.line);
2888
2912
  const bound = forward ? Object.keys(boundSites).filter((name) => name in liveSecrets) : [];
2889
2913
  for (const name of bound) {
2890
2914
  for (const site of boundSites[name])
@@ -3113,6 +3137,9 @@ mayDefer) {
3113
3137
  // cannot go through it, and the platform starts no account
3114
3138
  // browser pod for it (browse-egress.ts, FOL-110 phase 3).
3115
3139
  ...(browse?.kind === "hosted" ? { [BROWSER_CONFINED_ENV]: "1" } : {}),
3140
+ // The search door's address, for the driver: a step it walls
3141
+ // searches there, with the tool told it is held (search-egress.ts).
3142
+ ...(grant.search && lease?.search ? { [SEARCH_DOOR_ENV]: lease.search } : {}),
3116
3143
  // Only a step with a bound secret has a site the proxy
3117
3144
  // intercepts, so only that step's TLS clients are pointed at a
3118
3145
  // bundle with the egress CA in it; every other step's are as
@@ -226,7 +226,10 @@ export declare const ROOT_SHELL_GUARD_SH: string;
226
226
  * byte-identical (FOL-50): the tar carries that status whole and files built
227
227
  * against those exact packages, and a maintainer script reads the base as
228
228
  * well as writing to it. What keeps a snapshot valid across releases is the
229
- * image keeping its OS layers (run-container.ts, FOLDRUN_OS_REFRESH):
229
+ * image keeping its OS layers: the hosted runner is built FROM a base image
230
+ * pinned by digest (run-container.ts RUNNER_OS_DOCKERFILE, FOLDRUN_RUNNER_BASE_*;
231
+ * foldrun-infra images/runner-base.env), refreshed weekly or for a fixable
232
+ * critical vulnerability, so only a refresh moves the status file:
230
233
  *
231
234
  * - a base change is a new generation beside the old ones, counted in the
232
235
  * status file as `stale` (the run log says "N snapshots did not fit this
@@ -1045,7 +1045,10 @@ exit 0`;
1045
1045
  * byte-identical (FOL-50): the tar carries that status whole and files built
1046
1046
  * against those exact packages, and a maintainer script reads the base as
1047
1047
  * well as writing to it. What keeps a snapshot valid across releases is the
1048
- * image keeping its OS layers (run-container.ts, FOLDRUN_OS_REFRESH):
1048
+ * image keeping its OS layers: the hosted runner is built FROM a base image
1049
+ * pinned by digest (run-container.ts RUNNER_OS_DOCKERFILE, FOLDRUN_RUNNER_BASE_*;
1050
+ * foldrun-infra images/runner-base.env), refreshed weekly or for a fixable
1051
+ * critical vulnerability, so only a refresh moves the status file:
1049
1052
  *
1050
1053
  * - a base change is a new generation beside the old ones, counted in the
1051
1054
  * status file as `stale` (the run log says "N snapshots did not fit this
@@ -0,0 +1,58 @@
1
+ import type { NetworkLevel } from "./network.ts";
2
+ /** The `web` actions that ask a search engine when no provider answers them. */
3
+ export declare const SEARCHING_ACTIONS: readonly ["search", "answer", "monitor"];
4
+ export type SearchingAction = (typeof SEARCHING_ACTIONS)[number];
5
+ /** The searching actions a provider answers instead of our engine, from an
6
+ * agent's resolved `web:` block (webConfig(...).raw) — the runner's reading
7
+ * of it: a search API or a model provider's own search for `search`, an
8
+ * answer or monitor provider for those. */
9
+ export declare function searchProvided(raw: Record<string, unknown>): SearchingAction[];
10
+ /** What the proxy is told on the grant: the door is open for this step, and
11
+ * at most this many searches go through it. */
12
+ export interface SearchDoorGrant {
13
+ max?: number;
14
+ }
15
+ /**
16
+ * May this step search through the egress proxy's door? The runner asks,
17
+ * from its own resolved config — never the pod's environment — and after
18
+ * the lease, so `enforce` is the effective one (the install's switch too).
19
+ *
20
+ * Only a step held to a restricted list: the others reach the engine as
21
+ * before. Only the actions our engine answers. And where the list was made
22
+ * narrow on purpose — level `none` (only what the step declares) or
23
+ * `defaults: false` (no trusted list) — the action must be written out in
24
+ * `web: {actions: [...]}`: a bare `tools: [web]` does not open a way out for
25
+ * a query that the list's author never named. Every searching action gives
26
+ * any program in the step that same way out (curl can use the door too).
27
+ */
28
+ export declare function searchDoorWanted(o: {
29
+ level: NetworkLevel;
30
+ /** The trusted list is part of the step's list (network: defaults). */
31
+ defaults: boolean;
32
+ /** Will the proxy refuse a site off the list (the lease's enforce)? */
33
+ enforce: boolean;
34
+ /** The step has the web tool. */
35
+ web: boolean;
36
+ /** The `web: {actions: [...]}` in force, or null for all. */
37
+ actions: readonly string[] | null | undefined;
38
+ /** The searching actions a provider answers instead of our engine. */
39
+ provided: readonly SearchingAction[];
40
+ /** The step's `limits:` (cascaded), for the door's own count. */
41
+ limits?: Record<string, number>;
42
+ }): {
43
+ door: SearchDoorGrant | null;
44
+ line?: string;
45
+ };
46
+ /** The trace lines for a held step that is not given the door. */
47
+ export declare const SEARCH_NONE_UNNAMED = "search: not offered \u2014 this step's network: none allows only what it declares, and its web: block names no actions, so search is not one of them. Write web: {actions: [search, \u2026]} to let it search through the egress proxy.";
48
+ export declare const SEARCH_NO_DEFAULTS_UNNAMED = "search: not offered \u2014 this step's network: drops the trusted list (defaults: false), and its web: block names no actions, so search is not one of them. Write web: {actions: [search, \u2026]} to let it search through the egress proxy.";
49
+ /** The trace line a held step that searches carries, at its start. */
50
+ export declare const SEARCH_DOOR_LINE = "search: through the egress proxy \u2014 the account's search engine answers this step's queries from a fixed set of engines; a query's words leave for those engines, and each query is a line in this trace; a result is data, and fetching it is held to network: like any other site";
51
+ /** On a held step's sandbox beside the door's address: the web tool reads
52
+ * it to keep the address's path and to mark results as outside content. */
53
+ export declare const SEARCH_HELD_ENV = "FOLDRUN_SEARCH_HELD";
54
+ /** The runner's word to the platform's driver: the search door's address
55
+ * for this step (its grant carries `search`). The driver takes it out of
56
+ * the sandbox's environment and, for a step it walls, points the web tool
57
+ * there (FOLDRUN_SEARCH_URL, with SEARCH_HELD_ENV). */
58
+ export declare const SEARCH_DOOR_ENV = "FOLDRUN_SEARCH_DOOR";
@@ -0,0 +1,88 @@
1
+ // Web search and `network:` (FOL-128, foldrun-docs/network.md#search).
2
+ //
3
+ // A step held to its list — restricted (trusted or none), enforced, on the
4
+ // k8s tier — runs in a `filtered` pod: Cilium lets it reach the egress proxy
5
+ // and nothing else, and (FOLDRUN_RUN_DNS_WALL) it has no DNS. The account's
6
+ // search pod (SearXNG, which has the world) is not reachable from there. A
7
+ // named search API (`web: {search: brave}`) already works: its host is a
8
+ // site the step declares, and its key is filled at the proxy. foldrun's own
9
+ // engine did not: the tool was pointed at an address the wall drops.
10
+ //
11
+ // The semantics chosen (owner, 5 Nov 2026: search should work there):
12
+ //
13
+ // - The account's engine is a platform service, not a site on the list.
14
+ // A held step reaches it through the egress proxy's search door
15
+ // (`/s/<lease>/search`), lease-authenticated, and only when this
16
+ // module says the step searches our engine (grant.search, which the
17
+ // runner writes and the pod cannot). Nothing is added to the list.
18
+ // - A query is a message out — to the public engines SearXNG asks — so
19
+ // the door holds what it may say: only a fixed set of index engines
20
+ // (none that fetches a URL named in the query, none that federates to
21
+ // instances a query could name), no engine or bang chosen inside the
22
+ // query, no URL and no `${NAME}` placeholder in it. Every query is a
23
+ // line in the run trace, so what left is on the record.
24
+ // - Results are data. Nothing in them widens the list: fetching a result
25
+ // is a CONNECT through the proxy, held to the list like any other.
26
+ //
27
+ // Everything else — a step whose list is open or only reported, a step on
28
+ // an executor that walls nothing — searches exactly as before.
29
+ import { readSearchSettings, resolveSearch } from "./providers.js";
30
+ import { resolveActionApi } from "./web-actions.js";
31
+ /** The `web` actions that ask a search engine when no provider answers them. */
32
+ export const SEARCHING_ACTIONS = ["search", "answer", "monitor"];
33
+ /** The searching actions a provider answers instead of our engine, from an
34
+ * agent's resolved `web:` block (webConfig(...).raw) — the runner's reading
35
+ * of it: a search API or a model provider's own search for `search`, an
36
+ * answer or monitor provider for those. */
37
+ export function searchProvided(raw) {
38
+ const out = [];
39
+ const search = resolveSearch(readSearchSettings(raw.search).rest, "search");
40
+ if (search.provider && !search.error)
41
+ out.push("search");
42
+ for (const a of ["answer", "monitor"])
43
+ if (resolveActionApi(a, raw[a]).provider)
44
+ out.push(a);
45
+ return out;
46
+ }
47
+ /**
48
+ * May this step search through the egress proxy's door? The runner asks,
49
+ * from its own resolved config — never the pod's environment — and after
50
+ * the lease, so `enforce` is the effective one (the install's switch too).
51
+ *
52
+ * Only a step held to a restricted list: the others reach the engine as
53
+ * before. Only the actions our engine answers. And where the list was made
54
+ * narrow on purpose — level `none` (only what the step declares) or
55
+ * `defaults: false` (no trusted list) — the action must be written out in
56
+ * `web: {actions: [...]}`: a bare `tools: [web]` does not open a way out for
57
+ * a query that the list's author never named. Every searching action gives
58
+ * any program in the step that same way out (curl can use the door too).
59
+ */
60
+ export function searchDoorWanted(o) {
61
+ if (o.level === "open" || !o.enforce || !o.web)
62
+ return { door: null };
63
+ const ours = SEARCHING_ACTIONS.filter((a) => (!o.actions || o.actions.includes(a)) && !o.provided.includes(a));
64
+ if (!ours.length)
65
+ return { door: null };
66
+ if ((o.level === "none" || !o.defaults) && !o.actions) {
67
+ return { door: null, line: o.level === "none" ? SEARCH_NONE_UNNAMED : SEARCH_NO_DEFAULTS_UNNAMED };
68
+ }
69
+ // limits: — `web` bounds every action; else each searching action's own
70
+ // key, and only when every one this step may use has one.
71
+ const lim = o.limits ?? {};
72
+ const each = ours.map((a) => lim[`web.${a}`]);
73
+ const max = typeof lim.web === "number" ? lim.web : each.every((n) => typeof n === "number") ? each.reduce((s, n) => s + n, 0) : undefined;
74
+ return { door: max !== undefined ? { max } : {}, line: SEARCH_DOOR_LINE };
75
+ }
76
+ /** The trace lines for a held step that is not given the door. */
77
+ export const SEARCH_NONE_UNNAMED = "search: not offered — this step's network: none allows only what it declares, and its web: block names no actions, so search is not one of them. Write web: {actions: [search, …]} to let it search through the egress proxy.";
78
+ export const SEARCH_NO_DEFAULTS_UNNAMED = "search: not offered — this step's network: drops the trusted list (defaults: false), and its web: block names no actions, so search is not one of them. Write web: {actions: [search, …]} to let it search through the egress proxy.";
79
+ /** The trace line a held step that searches carries, at its start. */
80
+ export const SEARCH_DOOR_LINE = "search: through the egress proxy — the account's search engine answers this step's queries from a fixed set of engines; a query's words leave for those engines, and each query is a line in this trace; a result is data, and fetching it is held to network: like any other site";
81
+ /** On a held step's sandbox beside the door's address: the web tool reads
82
+ * it to keep the address's path and to mark results as outside content. */
83
+ export const SEARCH_HELD_ENV = "FOLDRUN_SEARCH_HELD";
84
+ /** The runner's word to the platform's driver: the search door's address
85
+ * for this step (its grant carries `search`). The driver takes it out of
86
+ * the sandbox's environment and, for a step it walls, points the web tool
87
+ * there (FOLDRUN_SEARCH_URL, with SEARCH_HELD_ENV). */
88
+ export const SEARCH_DOOR_ENV = "FOLDRUN_SEARCH_DOOR";
@@ -326,6 +326,9 @@ agents reference them by name. Bind one to the sites it is for
326
326
  the egress proxy fills \`\${NAME}\` in requests to those sites alone. Which sites
327
327
  a sandbox may reach at all is \`network:\` — open for an agent that reads the web,
328
328
  the trusted list plus what it declares for every other (\`foldrun agent network\`).
329
+ A step held to its list still searches the web through the proxy's search door;
330
+ at \`none\` or \`defaults: false\` write it out — \`web: {actions: [search, fetch]}\` —
331
+ because a query's words leave (\`foldrun docs network\`).
329
332
 
330
333
  ## Talking to a deployed workspace
331
334
 
@@ -18,6 +18,7 @@ import { type A2aPublication } from "./a2a-publish.ts";
18
18
  import { type RemoteSpec } from "./a2a-remotes.ts";
19
19
  import { type FailureExplained, type FailureFacts } from "./failure.ts";
20
20
  import { type NetworkPolicy } from "./network.ts";
21
+ import { type SearchingAction } from "./search-egress.ts";
21
22
  import { type WireFormat, type AuthShape } from "./providers.ts";
22
23
  /**
23
24
  * Single-workspace mode. When set, the workspace IS this directory — no
@@ -375,11 +376,19 @@ export interface AgentInfo {
375
376
  * its web providers' and its bound secrets' sites. */
376
377
  /** browses: the step may browse; enforceWanted and browseVendor are what
377
378
  * this folder says toward browseVerdict (FOL-110) — the install says the rest. */
379
+ /** search: this folder's half of search-egress.ts searchDoorWanted — the
380
+ * web tool, the actions written in web: (null: all), and the searching
381
+ * actions a provider answers (FOL-128). */
378
382
  network: NetworkPolicy & {
379
383
  readsWeb: boolean;
380
384
  browses: boolean;
381
385
  enforceWanted: boolean;
382
386
  browseVendor: string | null;
387
+ search: {
388
+ web: boolean;
389
+ actions: string[] | null;
390
+ provided: SearchingAction[];
391
+ };
383
392
  };
384
393
  /** Tools this agent declares inline rather than in `tools:` — `apis:`,
385
394
  * `scripts:` and `mcpServers:` names — which a limit may also name. */
package/dist/src/store.js CHANGED
@@ -53,6 +53,7 @@ import { timezoneProblem } from "./clock.js";
53
53
  import { parseStepLimits, readLimits } from "./limits.js";
54
54
  import { networkEnforceWanted, networkProblems, resolveNetwork } from "./network.js";
55
55
  import { browseVendorOf } from "./browse-egress.js";
56
+ import { searchProvided } from "./search-egress.js";
56
57
  import { webProblems, webWarnings, runnerEngines, webConfig } from "./providers.js";
57
58
  import { actionProblems } from "./web-actions.js";
58
59
  import { languageProblem } from "./language.js";
@@ -1185,6 +1186,11 @@ export function listAgents(tenant, workspace) {
1185
1186
  enforceWanted: networkEnforceWanted(accountFront.network_enforce, workspaceFront.network_enforce),
1186
1187
  // The vendor its web.browse names, null for foldrun's own browser.
1187
1188
  browseVendor: browseVendorOf(webConfig(data, { ...accountFront, ...workspaceFront }).raw.browse),
1189
+ search: {
1190
+ web: tools.includes("web"),
1191
+ actions: actions ? [...actions] : null,
1192
+ provided: searchProvided(webConfig(data, { ...accountFront, ...workspaceFront }).raw),
1193
+ },
1188
1194
  };
1189
1195
  return {
1190
1196
  network,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@foldrun/core",
3
- "version": "16.0.0",
3
+ "version": "17.0.0",
4
4
  "description": "Agents are just folders. The format, the runner, the checks.",
5
5
  "license": "FSL-1.1-ALv2",
6
6
  "type": "module",
package/src/egress.ts CHANGED
@@ -128,6 +128,10 @@ export interface EgressGrant {
128
128
  /** Identity name → the audience its tokens are for: the only identities
129
129
  * this step may ask the proxy's /identity door to mint (oidc-issuer.ts). */
130
130
  identities?: Record<string, { audience: string }>;
131
+ /** The proxy's search door is open for this step (search-egress.ts
132
+ * searchDoorWanted): a held step's way to the account's search engine.
133
+ * `max` caps how many searches go through it. Absent: the door refuses. */
134
+ search?: { max?: number };
131
135
  }
132
136
 
133
137
  export interface EgressLease {
@@ -140,6 +144,9 @@ export interface EgressLease {
140
144
  /** The PEM of the CA the forward door signs with for a host a secret is
141
145
  * bound to, so the sandbox can trust exactly those interceptions. */
142
146
  ca?: string;
147
+ /** The proxy's search door for this lease (`…/s/<token>`), when the
148
+ * proxy has one: where a held step's web search is sent. */
149
+ search?: string;
143
150
  /** Whether a site off the step's list is refused (true) or only named
144
151
  * in the trace (false). */
145
152
  enforce?: boolean;
package/src/platform.ts CHANGED
@@ -167,6 +167,14 @@ export interface PlatformHooks {
167
167
  * trace as not enforced.
168
168
  */
169
169
  confinesBrowsing?(isolation: string): boolean;
170
+ /**
171
+ * Does this isolation mode wall a step whose `network:` is restricted and
172
+ * enforced to the egress proxy alone (a `filtered` pod)? True: such a
173
+ * step's web search goes through the proxy's search door (FOL-128,
174
+ * search-egress.ts), since the account's search engine is out of its
175
+ * reach. Absent or false: it reaches the engine as it always did.
176
+ */
177
+ wallsRestricted?(isolation: string): boolean;
170
178
  /**
171
179
  * An operator setting, by the environment variable that used to hold it
172
180
  * (30 Oct 2026): the platform answers with the operator's value where one
@@ -1117,7 +1117,7 @@ export const RETRY_SH = `retry() { what=$1; shift; n=1; until "$@"; do if [ "$n"
1117
1117
  * RCE, TLS hostname bypasses); the pin before carried 22.23.3. */
1118
1118
  export const NODE_BASE = "node:22-trixie-slim@sha256:8eb619e402eaede1748a3c8173bffab391592812e85136452f781741c7242ddf";
1119
1119
 
1120
- // Two images from one file, as build targets.
1120
+ // Two images from one file, as build targets, in two parts.
1121
1121
  //
1122
1122
  // full (the default, the last stage) — everything, browsers included. The
1123
1123
  // per-account browser pod runs it, and so does any step that may
@@ -1130,10 +1130,44 @@ export const NODE_BASE = "node:22-trixie-slim@sha256:8eb619e402eaede1748a3c8173b
1130
1130
  // (run-k8s.ts picks), and its declared packages arrive at run time
1131
1131
  // through the runtime cache — uv is in the base for exactly that.
1132
1132
  //
1133
+ // The parts (FOL-50, 5 Nov 2026):
1134
+ //
1135
+ // the OS RUNNER_OS_DOCKERFILE: Debian, every apt package, uv, the
1136
+ // Playwright client and, for full, the browsers (Google's Chrome
1137
+ // included). Targets `slim-os` and `browsers`. Everything that
1138
+ // writes /var/lib/dpkg/status is here and nowhere else.
1139
+ // the app core and the driver on top (CORE_STAGE, CORE_INSTALL): files
1140
+ // only, no apt.
1141
+ //
1142
+ // Built together (runnerDockerfile() — a laptop, a self-hoster, images.yml)
1143
+ // it is one image as before. The hosted platform builds the OS part on its
1144
+ // own as the runner BASE image, pins it by digest (foldrun-infra
1145
+ // images/runner-base.env, refreshed weekly and at once for a fixable critical
1146
+ // vulnerability) and builds the app part FROM it (FOLDRUN_RUNNER_BASE_SLIM /
1147
+ // _FULL). A release that changes only foldrun's code then keeps the base's
1148
+ // bytes, so the dpkg status a `runtime: system:` snapshot was built on is
1149
+ // still there after the deploy (runtime.ts systemInstallSh) — rebuilding the
1150
+ // OS on every core change moved Chrome, the apt index and every package's
1151
+ // status line, and each release cost each package set a full apt install.
1152
+ //
1133
1153
  // The browsers sit BELOW the core install in `full`, as they always have,
1134
1154
  // so a core change rebuilds one thin layer and not 1.4 GB of Chromium.
1135
- export const DOCKERFILE = `FROM ${NODE_BASE} AS base
1155
+
1156
+ /** Stands for the OS definition's id inside its own text: the id is the
1157
+ * sha256 of the text with this in place, then substituted in. */
1158
+ const OS_ID_SLOT = "@@FOLDRUN_RUNNER_OS@@";
1159
+ /** The end of each OS target: which definition built it, as a label and as
1160
+ * a file the app part checks (OS_GUARD). Not under /var/lib/dpkg. */
1161
+ const OS_MARK = `LABEL io.foldrun.runner-os=${OS_ID_SLOT}
1162
+ RUN echo ${OS_ID_SLOT} > /etc/foldrun-runner-os`;
1163
+
1164
+ const OS_TEMPLATE = `FROM ${NODE_BASE} AS base
1165
+ # upgrade: node's image lags Debian security (the platform images learnt it
1166
+ # on 6 Oct 2026, perl-base), and the hosted runner's base is rebuilt weekly
1167
+ # precisely so those fixes arrive; without it a refresh changed nothing the
1168
+ # node image already carried.
1136
1169
  RUN apt-get update \\
1170
+ && DEBIAN_FRONTEND=noninteractive apt-get upgrade -y --no-install-recommends \\
1137
1171
  && apt-get install -y --no-install-recommends python3 python3-venv ca-certificates bash util-linux tar openssh-client sshpass git curl \\
1138
1172
  && rm -rf /var/lib/apt/lists/* \\
1139
1173
  && useradd -m -u 10001 agent
@@ -1142,8 +1176,7 @@ RUN apt-get update \\
1142
1176
  COPY --from=ghcr.io/astral-sh/uv:${UV_VERSION} /uv /uvx /usr/local/bin/
1143
1177
  ENV PLAYWRIGHT_BROWSERS_PATH=/opt/browser NODE_PATH=/usr/local/lib/node_modules
1144
1178
 
1145
- ${CORE_STAGE}
1146
- FROM base AS slim
1179
+ FROM base AS slim-os
1147
1180
  # Fonts, because a step that draws text without a browser still needs them:
1148
1181
  # the full image gets 51 from Playwright's --with-deps, slim had none, so from
1149
1182
  # 2026-09-29 (when non-browsing steps moved to slim) every resvg/sharp diagram
@@ -1169,7 +1202,8 @@ RUN apt-get update \\
1169
1202
  # npm's download cache is dropped in the same layer: it was 190 MB of every
1170
1203
  # image, read by nothing after the build.
1171
1204
  RUN npm install -g playwright@1.63.0 axe-core@4.13.0 >/dev/null && npm cache clean --force >/dev/null 2>&1
1172
- ${CORE_INSTALL}
1205
+ ${OS_MARK}
1206
+
1173
1207
  FROM base AS browsers
1174
1208
  # Real browsers, because directories and portals increasingly render with
1175
1209
  # JavaScript and a plain fetch sees only the empty shell. Chromium is the one the
@@ -1294,9 +1328,74 @@ RUN node -e ' \\
1294
1328
  if (missing.length) console.error("runner image: built without " + missing.join(", ") + " on " + arch); \\
1295
1329
  ' \\
1296
1330
  && chmod a+r /opt/browser/engines.json
1331
+ ${OS_MARK}
1332
+ `;
1333
+
1334
+ /** Which definition of the OS part this core holds: 16 hex of the sha256 of
1335
+ * its text. A base image carries it (label io.foldrun.runner-os and
1336
+ * /etc/foldrun-runner-os); a base from another definition is refused. */
1337
+ export const RUNNER_OS_ID = crypto.createHash("sha256").update(OS_TEMPLATE).digest("hex").slice(0, 16);
1338
+
1339
+ /** The runner's OS part on its own — what the base image is built from
1340
+ * (targets RUNNER_OS_TARGETS). No build context: it copies nothing local. */
1341
+ export const RUNNER_OS_DOCKERFILE = OS_TEMPLATE.split(OS_ID_SLOT).join(RUNNER_OS_ID);
1342
+
1343
+ /** The OS part's build target for each runner variant. */
1344
+ export const RUNNER_OS_TARGETS = { slim: "slim-os", full: "browsers" } as const;
1345
+
1346
+ /** The app part's first word in both variants: the OS under it is the one
1347
+ * this core's text describes. A base built from an older definition (a
1348
+ * Playwright bump, a new apt package) would otherwise ship a runner whose
1349
+ * browsers or packages are not the ones its core expects. */
1350
+ const OS_GUARD = `RUN test "$(cat /etc/foldrun-runner-os 2>/dev/null)" = "${RUNNER_OS_ID}" \\
1351
+ || { echo "runner image: its base was built from another definition (wants ${RUNNER_OS_ID}, has $(cat /etc/foldrun-runner-os 2>/dev/null || echo none)) - build the base again: bash foldrun-infra/dev/ci/runner-base.sh refresh" >&2; exit 1; }`;
1352
+
1353
+ /** The base images a runner is built FROM, by digest, one per variant. */
1354
+ export type RunnerBase = { slim: string; full: string };
1355
+
1356
+ const BASE_REF = /^[a-z0-9][a-z0-9._/:-]*@sha256:[0-9a-f]{64}$/;
1297
1357
 
1358
+ /**
1359
+ * The runner base from FOLDRUN_RUNNER_BASE_SLIM and FOLDRUN_RUNNER_BASE_FULL:
1360
+ * both or neither (empty counts as unset, as FOLDRUN_RUNNER_IMAGE does), each
1361
+ * an image by digest — a tag would let the same runner tag hold another
1362
+ * base's bytes. Anything else throws: a half-set base is a broken deploy,
1363
+ * not a reason to quietly build the OS again.
1364
+ */
1365
+ export function runnerBase(env: NodeJS.ProcessEnv = process.env): RunnerBase | null {
1366
+ const slim = env.FOLDRUN_RUNNER_BASE_SLIM ?? "";
1367
+ const full = env.FOLDRUN_RUNNER_BASE_FULL ?? "";
1368
+ if (!slim && !full) return null;
1369
+ if (!slim || !full) {
1370
+ throw new Error("FOLDRUN_RUNNER_BASE_SLIM and FOLDRUN_RUNNER_BASE_FULL go together: set both (the base's two images, by digest) or neither");
1371
+ }
1372
+ for (const [k, v] of [["FOLDRUN_RUNNER_BASE_SLIM", slim], ["FOLDRUN_RUNNER_BASE_FULL", full]] as const) {
1373
+ if (!BASE_REF.test(v)) throw new Error(`${k} must name an image by digest (name@sha256:<64 hex>), not ${JSON.stringify(v.slice(0, 120))}`);
1374
+ }
1375
+ return { slim, full };
1376
+ }
1377
+
1378
+ /**
1379
+ * The runner's Dockerfile: with no base, the OS part and the app part in one
1380
+ * file (a self-contained build); with one, the app part FROM the base's two
1381
+ * images. The app part's text is the same either way.
1382
+ */
1383
+ export function runnerDockerfile(base: RunnerBase | null = null): string {
1384
+ const os = base
1385
+ ? `FROM ${base.slim} AS slim-os\nFROM ${base.full} AS browsers\nFROM slim-os AS base\n`
1386
+ : RUNNER_OS_DOCKERFILE;
1387
+ return `${os}
1388
+ ${CORE_STAGE}
1389
+ FROM slim-os AS slim
1390
+ ${OS_GUARD}
1391
+ ${CORE_INSTALL}
1298
1392
  FROM browsers AS full
1393
+ ${OS_GUARD}
1299
1394
  ${CORE_INSTALL}`;
1395
+ }
1396
+
1397
+ /** The self-contained runner Dockerfile (no base): runnerDockerfile(). */
1398
+ export const DOCKERFILE = runnerDockerfile();
1300
1399
 
1301
1400
  // runtime: system: — apt as root, before the drop (runtime.ts systemInstallSh).
1302
1401
  // set -e is off around it: a failed install is reported by the driver, which
@@ -1342,7 +1441,9 @@ export function runnerImageTag(variant: RunnerVariant = "full"): string {
1342
1441
  // The fingerprint hashes the *built code*, not the version — a version
1343
1442
  // string that nobody bumped would pin every future run to the runner
1344
1443
  // image of whatever core happened to build first.
1345
- const hash = crypto.createHash("sha256").update(DRIVER + "\n" + DOCKERFILE + "\n" + ENTRY);
1444
+ // The Dockerfile as it will be built — with the base's digests in it when
1445
+ // one is set, so a new base is a new tag.
1446
+ const hash = crypto.createHash("sha256").update(DRIVER + "\n" + runnerDockerfile(runnerBase()) + "\n" + ENTRY);
1346
1447
  const dist = path.join(corePackageDir(), "dist");
1347
1448
  if (fs.existsSync(dist)) {
1348
1449
  for (const entry of fs.readdirSync(dist, { recursive: true }).sort()) {
@@ -1391,6 +1492,12 @@ export function ensureRunnerImage(
1391
1492
  const { tag, explicit } = runnerImageRef(opts);
1392
1493
  const log: string[] = [];
1393
1494
  if (explicit) return { tag, log };
1495
+ const base = runnerBase();
1496
+ // A base is one platform's images (the hosted base is linux/amd64): a
1497
+ // cross-build on it would pull the wrong arch or none.
1498
+ if (base && opts.platform) {
1499
+ throw new Error(`a runner base names one platform's images: unset FOLDRUN_RUNNER_BASE_SLIM and FOLDRUN_RUNNER_BASE_FULL to build for ${opts.platform}`);
1500
+ }
1394
1501
 
1395
1502
  const have = spawnSync(cli(), ["image", "inspect", tag], { stdio: "ignore" });
1396
1503
  if (have.status === 0) return { tag, log };
@@ -1405,8 +1512,9 @@ export function ensureRunnerImage(
1405
1512
  fs.renameSync(path.join(build, tarball), path.join(build, "foldrun-core.tgz"));
1406
1513
  fs.writeFileSync(path.join(build, "driver.mjs"), DRIVER);
1407
1514
  fs.writeFileSync(path.join(build, "entry.sh"), ENTRY);
1408
- fs.writeFileSync(path.join(build, "Dockerfile"), DOCKERFILE);
1409
- log.push(`building runner image ${tag} (first run only)`);
1515
+ // The same text the tag hashed (runnerImageTag), base and all.
1516
+ fs.writeFileSync(path.join(build, "Dockerfile"), runnerDockerfile(base));
1517
+ log.push(`building runner image ${tag} (first run only)${base ? ` on base ${base.full.split("@")[1].slice(7, 19)}` : ""}`);
1410
1518
  const args = [
1411
1519
  "build",
1412
1520
  ...(opts.platform ? ["--platform", opts.platform] : []),
package/src/runner.ts CHANGED
@@ -103,6 +103,7 @@ import { loadCatalog, checkModel, clampEffort, catalogCost, findModel, tokenPric
103
103
  import { resolveSecrets, getSecret, materializeSecrets, secretSites, isClientCertValue, clientCertOf, withoutHeldCerts, isIdentityValue, identityOf } from "./secrets.ts";
104
104
  import { resolveNetwork, networkLine, networkEnforceWanted, proxyEnv, siteCovers, EGRESS_CA_ENV } from "./network.ts";
105
105
  import { BROWSER_CONFINED_ENV, browseNetworkLine, browseVerdict } from "./browse-egress.ts";
106
+ import { SEARCH_DOOR_ENV, searchDoorWanted, searchProvided } from "./search-egress.ts";
106
107
  import { materializeFileSecrets, cleanupFileSecrets } from "./secret-files.ts";
107
108
  import { buildApiTools, secretsUsedByApi } from "./api-tools.ts";
108
109
  import { buildA2ATools } from "./a2a-tools.ts";
@@ -3094,6 +3095,26 @@ async function runStep(
3094
3095
  // A browsing step on an install with the door says whether it is held
3095
3096
  // to its list, and which tier its browser falls in (browse-egress.ts).
3096
3097
  push("info", browse ? browseNetworkLine(network, clockEnv.FOLDRUN_BROWSER_VENDOR, { hosted: browse.kind === "hosted" }) : networkLine(network, forward ? forward.enforce === true : null));
3098
+ // Web search under a held list (FOL-128, search-egress.ts): the
3099
+ // account's engine through the proxy's search door, for the actions
3100
+ // our engine answers — decided here, from this step's own config and
3101
+ // the lease's effective enforce, and carried on the grant, which the
3102
+ // pod cannot write. Only where the executor walls such a step (the
3103
+ // others reach the engine directly). Off a held list: nothing here.
3104
+ const searchDoor = forward && !!isolation && platform.wallsRestricted?.(isolation) === true
3105
+ ? searchDoorWanted({
3106
+ level: network.level,
3107
+ defaults: network.defaults,
3108
+ enforce: forward.enforce === true,
3109
+ web: scriptSpecs.some((sc) => sc.name === "web"),
3110
+ actions: web.actions ?? null,
3111
+ provided: searchProvided(web.raw),
3112
+ limits: stepLimits,
3113
+ })
3114
+ : { door: null };
3115
+ if (searchDoor.door) grant.search = searchDoor.door;
3116
+ else delete grant.search;
3117
+ if (searchDoor.line) push("info", searchDoor.line);
3097
3118
  const bound = forward ? Object.keys(boundSites).filter((name) => name in liveSecrets) : [];
3098
3119
  for (const name of bound) {
3099
3120
  for (const site of boundSites[name]) addGrant(grant, name, liveSecrets[name], site);
@@ -3326,6 +3347,9 @@ async function runStep(
3326
3347
  // cannot go through it, and the platform starts no account
3327
3348
  // browser pod for it (browse-egress.ts, FOL-110 phase 3).
3328
3349
  ...(browse?.kind === "hosted" ? { [BROWSER_CONFINED_ENV]: "1" } : {}),
3350
+ // The search door's address, for the driver: a step it walls
3351
+ // searches there, with the tool told it is held (search-egress.ts).
3352
+ ...(grant.search && lease?.search ? { [SEARCH_DOOR_ENV]: lease.search } : {}),
3329
3353
  // Only a step with a bound secret has a site the proxy
3330
3354
  // intercepts, so only that step's TLS clients are pointed at a
3331
3355
  // bundle with the egress CA in it; every other step's are as
package/src/runtime.ts CHANGED
@@ -1093,7 +1093,10 @@ exit 0`;
1093
1093
  * byte-identical (FOL-50): the tar carries that status whole and files built
1094
1094
  * against those exact packages, and a maintainer script reads the base as
1095
1095
  * well as writing to it. What keeps a snapshot valid across releases is the
1096
- * image keeping its OS layers (run-container.ts, FOLDRUN_OS_REFRESH):
1096
+ * image keeping its OS layers: the hosted runner is built FROM a base image
1097
+ * pinned by digest (run-container.ts RUNNER_OS_DOCKERFILE, FOLDRUN_RUNNER_BASE_*;
1098
+ * foldrun-infra images/runner-base.env), refreshed weekly or for a fixable
1099
+ * critical vulnerability, so only a refresh moves the status file:
1097
1100
  *
1098
1101
  * - a base change is a new generation beside the old ones, counted in the
1099
1102
  * status file as `stale` (the run log says "N snapshots did not fit this
@@ -0,0 +1,116 @@
1
+ // Web search and `network:` (FOL-128, foldrun-docs/network.md#search).
2
+ //
3
+ // A step held to its list — restricted (trusted or none), enforced, on the
4
+ // k8s tier — runs in a `filtered` pod: Cilium lets it reach the egress proxy
5
+ // and nothing else, and (FOLDRUN_RUN_DNS_WALL) it has no DNS. The account's
6
+ // search pod (SearXNG, which has the world) is not reachable from there. A
7
+ // named search API (`web: {search: brave}`) already works: its host is a
8
+ // site the step declares, and its key is filled at the proxy. foldrun's own
9
+ // engine did not: the tool was pointed at an address the wall drops.
10
+ //
11
+ // The semantics chosen (owner, 5 Nov 2026: search should work there):
12
+ //
13
+ // - The account's engine is a platform service, not a site on the list.
14
+ // A held step reaches it through the egress proxy's search door
15
+ // (`/s/<lease>/search`), lease-authenticated, and only when this
16
+ // module says the step searches our engine (grant.search, which the
17
+ // runner writes and the pod cannot). Nothing is added to the list.
18
+ // - A query is a message out — to the public engines SearXNG asks — so
19
+ // the door holds what it may say: only a fixed set of index engines
20
+ // (none that fetches a URL named in the query, none that federates to
21
+ // instances a query could name), no engine or bang chosen inside the
22
+ // query, no URL and no `${NAME}` placeholder in it. Every query is a
23
+ // line in the run trace, so what left is on the record.
24
+ // - Results are data. Nothing in them widens the list: fetching a result
25
+ // is a CONNECT through the proxy, held to the list like any other.
26
+ //
27
+ // Everything else — a step whose list is open or only reported, a step on
28
+ // an executor that walls nothing — searches exactly as before.
29
+
30
+ import type { NetworkLevel } from "./network.ts";
31
+ import { readSearchSettings, resolveSearch } from "./providers.ts";
32
+ import { resolveActionApi } from "./web-actions.ts";
33
+
34
+ /** The `web` actions that ask a search engine when no provider answers them. */
35
+ export const SEARCHING_ACTIONS = ["search", "answer", "monitor"] as const;
36
+ export type SearchingAction = (typeof SEARCHING_ACTIONS)[number];
37
+
38
+ /** The searching actions a provider answers instead of our engine, from an
39
+ * agent's resolved `web:` block (webConfig(...).raw) — the runner's reading
40
+ * of it: a search API or a model provider's own search for `search`, an
41
+ * answer or monitor provider for those. */
42
+ export function searchProvided(raw: Record<string, unknown>): SearchingAction[] {
43
+ const out: SearchingAction[] = [];
44
+ const search = resolveSearch(readSearchSettings(raw.search).rest, "search");
45
+ if (search.provider && !search.error) out.push("search");
46
+ for (const a of ["answer", "monitor"] as const) if (resolveActionApi(a, raw[a]).provider) out.push(a);
47
+ return out;
48
+ }
49
+
50
+ /** What the proxy is told on the grant: the door is open for this step, and
51
+ * at most this many searches go through it. */
52
+ export interface SearchDoorGrant {
53
+ max?: number;
54
+ }
55
+
56
+ /**
57
+ * May this step search through the egress proxy's door? The runner asks,
58
+ * from its own resolved config — never the pod's environment — and after
59
+ * the lease, so `enforce` is the effective one (the install's switch too).
60
+ *
61
+ * Only a step held to a restricted list: the others reach the engine as
62
+ * before. Only the actions our engine answers. And where the list was made
63
+ * narrow on purpose — level `none` (only what the step declares) or
64
+ * `defaults: false` (no trusted list) — the action must be written out in
65
+ * `web: {actions: [...]}`: a bare `tools: [web]` does not open a way out for
66
+ * a query that the list's author never named. Every searching action gives
67
+ * any program in the step that same way out (curl can use the door too).
68
+ */
69
+ export function searchDoorWanted(o: {
70
+ level: NetworkLevel;
71
+ /** The trusted list is part of the step's list (network: defaults). */
72
+ defaults: boolean;
73
+ /** Will the proxy refuse a site off the list (the lease's enforce)? */
74
+ enforce: boolean;
75
+ /** The step has the web tool. */
76
+ web: boolean;
77
+ /** The `web: {actions: [...]}` in force, or null for all. */
78
+ actions: readonly string[] | null | undefined;
79
+ /** The searching actions a provider answers instead of our engine. */
80
+ provided: readonly SearchingAction[];
81
+ /** The step's `limits:` (cascaded), for the door's own count. */
82
+ limits?: Record<string, number>;
83
+ }): { door: SearchDoorGrant | null; line?: string } {
84
+ if (o.level === "open" || !o.enforce || !o.web) return { door: null };
85
+ const ours = SEARCHING_ACTIONS.filter((a) => (!o.actions || o.actions.includes(a)) && !o.provided.includes(a));
86
+ if (!ours.length) return { door: null };
87
+ if ((o.level === "none" || !o.defaults) && !o.actions) {
88
+ return { door: null, line: o.level === "none" ? SEARCH_NONE_UNNAMED : SEARCH_NO_DEFAULTS_UNNAMED };
89
+ }
90
+ // limits: — `web` bounds every action; else each searching action's own
91
+ // key, and only when every one this step may use has one.
92
+ const lim = o.limits ?? {};
93
+ const each = ours.map((a) => lim[`web.${a}`]);
94
+ const max = typeof lim.web === "number" ? lim.web : each.every((n) => typeof n === "number") ? each.reduce((s, n) => s + (n as number), 0) : undefined;
95
+ return { door: max !== undefined ? { max } : {}, line: SEARCH_DOOR_LINE };
96
+ }
97
+
98
+ /** The trace lines for a held step that is not given the door. */
99
+ export const SEARCH_NONE_UNNAMED =
100
+ "search: not offered — this step's network: none allows only what it declares, and its web: block names no actions, so search is not one of them. Write web: {actions: [search, …]} to let it search through the egress proxy.";
101
+ export const SEARCH_NO_DEFAULTS_UNNAMED =
102
+ "search: not offered — this step's network: drops the trusted list (defaults: false), and its web: block names no actions, so search is not one of them. Write web: {actions: [search, …]} to let it search through the egress proxy.";
103
+
104
+ /** The trace line a held step that searches carries, at its start. */
105
+ export const SEARCH_DOOR_LINE =
106
+ "search: through the egress proxy — the account's search engine answers this step's queries from a fixed set of engines; a query's words leave for those engines, and each query is a line in this trace; a result is data, and fetching it is held to network: like any other site";
107
+
108
+ /** On a held step's sandbox beside the door's address: the web tool reads
109
+ * it to keep the address's path and to mark results as outside content. */
110
+ export const SEARCH_HELD_ENV = "FOLDRUN_SEARCH_HELD";
111
+
112
+ /** The runner's word to the platform's driver: the search door's address
113
+ * for this step (its grant carries `search`). The driver takes it out of
114
+ * the sandbox's environment and, for a step it walls, points the web tool
115
+ * there (FOLDRUN_SEARCH_URL, with SEARCH_HELD_ENV). */
116
+ export const SEARCH_DOOR_ENV = "FOLDRUN_SEARCH_DOOR";
package/src/starter.ts CHANGED
@@ -342,6 +342,9 @@ agents reference them by name. Bind one to the sites it is for
342
342
  the egress proxy fills \`\${NAME}\` in requests to those sites alone. Which sites
343
343
  a sandbox may reach at all is \`network:\` — open for an agent that reads the web,
344
344
  the trusted list plus what it declares for every other (\`foldrun agent network\`).
345
+ A step held to its list still searches the web through the proxy's search door;
346
+ at \`none\` or \`defaults: false\` write it out — \`web: {actions: [search, fetch]}\` —
347
+ because a query's words leave (\`foldrun docs network\`).
345
348
 
346
349
  ## Talking to a deployed workspace
347
350
 
package/src/store.ts CHANGED
@@ -58,6 +58,7 @@ import { timezoneProblem } from "./clock.ts";
58
58
  import { parseStepLimits, readLimits } from "./limits.ts";
59
59
  import { networkEnforceWanted, networkProblems, resolveNetwork, type NetworkPolicy } from "./network.ts";
60
60
  import { browseVendorOf } from "./browse-egress.ts";
61
+ import { searchProvided, type SearchingAction } from "./search-egress.ts";
61
62
  import { webProblems, webWarnings, runnerEngines, webConfig } from "./providers.ts";
62
63
  import { actionProblems } from "./web-actions.ts";
63
64
  import { languageProblem } from "./language.ts";
@@ -1054,7 +1055,16 @@ export interface AgentInfo {
1054
1055
  * its web providers' and its bound secrets' sites. */
1055
1056
  /** browses: the step may browse; enforceWanted and browseVendor are what
1056
1057
  * this folder says toward browseVerdict (FOL-110) — the install says the rest. */
1057
- network: NetworkPolicy & { readsWeb: boolean; browses: boolean; enforceWanted: boolean; browseVendor: string | null };
1058
+ /** search: this folder's half of search-egress.ts searchDoorWanted — the
1059
+ * web tool, the actions written in web: (null: all), and the searching
1060
+ * actions a provider answers (FOL-128). */
1061
+ network: NetworkPolicy & {
1062
+ readsWeb: boolean;
1063
+ browses: boolean;
1064
+ enforceWanted: boolean;
1065
+ browseVendor: string | null;
1066
+ search: { web: boolean; actions: string[] | null; provided: SearchingAction[] };
1067
+ };
1058
1068
  /** Tools this agent declares inline rather than in `tools:` — `apis:`,
1059
1069
  * `scripts:` and `mcpServers:` names — which a limit may also name. */
1060
1070
  inlineTools: string[];
@@ -1688,6 +1698,11 @@ export function listAgents(tenant: string, workspace: string): AgentInfo[] {
1688
1698
  enforceWanted: networkEnforceWanted(accountFront.network_enforce, workspaceFront.network_enforce),
1689
1699
  // The vendor its web.browse names, null for foldrun's own browser.
1690
1700
  browseVendor: browseVendorOf(webConfig(data, { ...accountFront, ...workspaceFront }).raw.browse),
1701
+ search: {
1702
+ web: tools.includes("web"),
1703
+ actions: actions ? [...actions] : null,
1704
+ provided: searchProvided(webConfig(data, { ...accountFront, ...workspaceFront }).raw),
1705
+ },
1691
1706
  };
1692
1707
  return {
1693
1708
  network,