@foldrun/core 14.5.0 → 15.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.
@@ -1,11 +1,52 @@
1
- import { type NetworkPolicy } from "./network.ts";
1
+ import { type NetworkLevel, type NetworkPolicy } from "./network.ts";
2
2
  export type BrowseTier = "hosted" | "vendor" | "none";
3
+ /** Set to "1" in a browsing step held to its list (browseVerdict "hosted"):
4
+ * the web tool gives its browser the forward door as launch options and
5
+ * refuses what cannot go through it; the platform starts no account browser
6
+ * pod for the step (its pod could not reach one, and that pod is not walled). */
7
+ export declare const BROWSER_CONFINED_ENV = "FOLDRUN_BROWSER_CONFINED";
8
+ /** The vendor a `web.browse` value names (the runner's FOLDRUN_BROWSER_VENDOR),
9
+ * or null for foldrun's own browser — read the way runner.ts reads it. */
10
+ export declare function browseVendorOf(browse: unknown): string | null;
3
11
  /** Which tier a step's browser falls in: no vendor (or foldrun) is ours. */
4
12
  export declare function browseTier(vendor: string | null | undefined): {
5
13
  tier: BrowseTier;
6
14
  title: string;
7
15
  };
16
+ /** How one browsing step is held to its `network:` list:
17
+ *
18
+ * legacy — as before phase 3: no forward proxy, the pod keeps the world,
19
+ * and the trace says the list does not hold. An open list, a
20
+ * report-only install, or an executor that cannot wall the
21
+ * step's network.
22
+ * hosted — enforced: the step gets the forward proxy, its pod is walled
23
+ * to the egress proxy and DNS, and foldrun's browser runs in it.
24
+ * refuse — a vendor's browser under a restricted, enforced list on an
25
+ * install that holds browsing: it browses from the vendor's
26
+ * network, which nothing here can hold to the list, so the step
27
+ * is refused before anything connects (decision 4). */
28
+ export type BrowseVerdict = {
29
+ kind: "legacy";
30
+ } | {
31
+ kind: "hosted";
32
+ } | {
33
+ kind: "refuse";
34
+ message: string;
35
+ };
36
+ export declare function browseVerdict(o: {
37
+ /** The step's resolved level (network.ts). */
38
+ level: NetworkLevel;
39
+ /** Will the proxy refuse a site off the list (lease.enforce)? */
40
+ enforce: boolean;
41
+ /** FOLDRUN_BROWSER_VENDOR: the vendor the agent named, if any. */
42
+ vendor: string | null | undefined;
43
+ /** Can this executor wall the step's network (Platform.confinesBrowsing)? */
44
+ confines: boolean;
45
+ }): BrowseVerdict;
8
46
  /** The trace's network line for a step that may browse, on an install with
9
- * an egress proxy: the step's list, and the plain fact that it does not
10
- * hold yet — for the browser or anything else in the step. */
11
- export declare function browseNetworkLine(policy: NetworkPolicy, vendor: string | null | undefined): string;
47
+ * an egress proxy: the step's list, and whether it holds — `hosted` when
48
+ * browseVerdict put the step under the wall, else the plain fact that it
49
+ * does not hold yet, for the browser or anything else in the step. */
50
+ export declare function browseNetworkLine(policy: NetworkPolicy, vendor: string | null | undefined, opts?: {
51
+ hosted?: boolean;
52
+ }): string;
@@ -1,22 +1,42 @@
1
1
  // Browsing and `network:` (FOL-110, foldrun-docs/proposals/browse-egress.md).
2
2
  //
3
- // A step that may browse is not held to its `network:` list yet: the runner
4
- // gives it no forward proxy (a browser in the sandbox cannot send credentials
5
- // written into a proxy URL), so the browser — and every other program in that
6
- // step — reaches sites directly. Until the browse service and hosted
7
- // enforcement ship, the trace says so plainly, and says which of the three
8
- // tiers this step's browser will fall in:
3
+ // Three tiers, said in the trace:
9
4
  //
10
5
  // hosted — foldrun's own browser (the account's browser pod, Lightpanda,
11
- // Obscura, a live session): our network boundary will confine it.
6
+ // Obscura, a live session): our network boundary confines it.
12
7
  // vendor — a vendor that takes a customer proxy (Browserbase, Steel,
13
8
  // Hyperbrowser, Browserless): through the egress proxy, enforced
14
- // once that vendor is qualified by our own tests.
9
+ // once that vendor is qualified by our own tests (phase 4).
15
10
  // none — a vendor that always browses through its own network (Bright
16
11
  // Data, ZenRows) or any DevTools address: never enforced; a
17
- // restricted, enforced `network:` will refuse it.
18
- import { findBrowserApi } from "./providers.js";
12
+ // restricted, enforced `network:` refuses it.
13
+ //
14
+ // Phase 3 (hosted enforcement) holds a browsing step to its list where the
15
+ // executor can wall the step's network (the k8s tier, with the install's
16
+ // FOLDRUN_BROWSE_ENFORCE=1 — Platform.confinesBrowsing). Such a step gets the
17
+ // forward proxy like any other, so its run pod is `filtered`: it reaches the
18
+ // egress proxy and DNS and nothing else, and the browser runs inside it, in
19
+ // the step's own pod. A client that sets another proxy, a CDP context with
20
+ // its own proxyServer, a curl that ignores HTTPS_PROXY — each finds no route,
21
+ // never a way round the list. Not covered: DNS lookups through the cluster's
22
+ // resolver, which the wall admits and nothing here restricts. browseVerdict
23
+ // says, for one step, which of the three ways it goes; everywhere else (no
24
+ // wall, an open or report-only list) the step browses as it did before
25
+ // phase 3, and the trace says so.
26
+ import { findBrowserApi, readBrowseSettings, resolveSearch } from "./providers.js";
19
27
  import { networkLine } from "./network.js";
28
+ /** Set to "1" in a browsing step held to its list (browseVerdict "hosted"):
29
+ * the web tool gives its browser the forward door as launch options and
30
+ * refuses what cannot go through it; the platform starts no account browser
31
+ * pod for the step (its pod could not reach one, and that pod is not walled). */
32
+ export const BROWSER_CONFINED_ENV = "FOLDRUN_BROWSER_CONFINED";
33
+ /** The vendor a `web.browse` value names (the runner's FOLDRUN_BROWSER_VENDOR),
34
+ * or null for foldrun's own browser — read the way runner.ts reads it. */
35
+ export function browseVendorOf(browse) {
36
+ const read = readBrowseSettings(browse);
37
+ const choice = resolveSearch(read.rest, "browse");
38
+ return choice.shape === "direct" && choice.provider ? choice.provider : null;
39
+ }
20
40
  /** Which tier a step's browser falls in: no vendor (or foldrun) is ours. */
21
41
  export function browseTier(vendor) {
22
42
  const name = (vendor ?? "").trim().toLowerCase();
@@ -27,15 +47,37 @@ export function browseTier(vendor) {
27
47
  return { tier: "none", title: name };
28
48
  return { tier: api.egress === "proxy" ? "vendor" : "none", title: api.title };
29
49
  }
50
+ export function browseVerdict(o) {
51
+ if (o.level === "open" || !o.enforce || !o.confines)
52
+ return { kind: "legacy" };
53
+ const { tier, title } = browseTier(o.vendor);
54
+ if (tier === "hosted")
55
+ return { kind: "hosted" };
56
+ const why = tier === "vendor"
57
+ ? `${title} browses from its own network, and foldrun cannot hold it to network: until that vendor is qualified (FOL-110 phase 4)`
58
+ : `${title} always browses through its own network, and nothing can hold it to network:`;
59
+ return {
60
+ kind: "refuse",
61
+ message: `browse: refused before it connected — this step's network: ${o.level} is enforced, and ${why}. ` +
62
+ `Drop browse: ${(o.vendor ?? "").trim()} from the agent's web: block to browse with foldrun's own browser, which is held to the list; ` +
63
+ `or, to accept browsing that no list holds for this one agent, give that agent network: open.`,
64
+ };
65
+ }
30
66
  /** The trace's network line for a step that may browse, on an install with
31
- * an egress proxy: the step's list, and the plain fact that it does not
32
- * hold yet — for the browser or anything else in the step. */
33
- export function browseNetworkLine(policy, vendor) {
34
- const { tier, title } = browseTier(vendor);
67
+ * an egress proxy: the step's list, and whether it holds — `hosted` when
68
+ * browseVerdict put the step under the wall, else the plain fact that it
69
+ * does not hold yet, for the browser or anything else in the step. */
70
+ export function browseNetworkLine(policy, vendor, opts = {}) {
35
71
  const what = networkLine(policy, true);
36
- const now = " — not enforced in this step: it may browse, and browsing does not go through the egress proxy yet, so the browser and every other program in this step reach sites directly";
72
+ if (opts.hosted) {
73
+ return `${what} — enforced — hosted: the browser runs inside this step's sandbox, whose network reaches only the egress proxy (which holds the list) and DNS, so a page, a script or a changed proxy setting reaches no site off the list; DNS lookups themselves are not restricted.`;
74
+ }
75
+ const { tier, title } = browseTier(vendor);
76
+ const now = " — not enforced in this step: it may browse, and browsing does not go through the egress proxy here, so the browser and every other program in this step reach sites directly";
37
77
  const later = tier === "hosted"
38
- ? `. Its browser is ${title}: it comes under network: when hosted enforcement ships (FOL-110)`
78
+ ? policy.level === "open"
79
+ ? `. Its browser is ${title}; with an open list there is nothing to hold it to`
80
+ : `. Its browser is ${title}: it is held to network: on an install that confines browsing, with the list enforced (FOL-110)`
39
81
  : tier === "vendor"
40
82
  ? `. Its browser (${title}) browses from the vendor's network: it comes under network: through the egress proxy once that vendor is qualified (FOL-110)`
41
83
  : `. Its browser (${title}) always browses through its own network and cannot be held to network: — a restricted, enforced network: will refuse it (FOL-110)`;
@@ -83,9 +83,13 @@ export interface PlatformHooks {
83
83
  * recorded — the delivery as seen, the throttle window — so the sender's
84
84
  * retry is a fresh event rather than a "duplicate" of a run that never
85
85
  * existed. Default: nothing, because the default gate records nothing. */
86
- rollbackTrigger(tenant: string, workspace: string, flow: FlowInfo, opts?: {
86
+ rollbackTrigger(tenant: string, workspace: string, flow: FlowInfo,
87
+ /** `code`: the refusal's own code, when it had one — `waiting_cap`
88
+ * is logged as `queue-full` rather than `failed`. */
89
+ opts?: {
87
90
  deliveryKey?: string | null;
88
91
  reason?: string;
92
+ code?: string;
89
93
  }): Promise<void>;
90
94
  /** Step executors by FOLDRUN_RUN_ISOLATION value, beyond the `container`
91
95
  * one core ships. The platform adds `k8s`. */
@@ -148,6 +152,16 @@ export interface PlatformHooks {
148
152
  * only where no provider: block of the account's own says otherwise.
149
153
  * Absent: nobody can (a laptop, a self-hosted install). */
150
154
  modelSupply?(tenant: string): SupplyAnswer;
155
+ /**
156
+ * Does this isolation mode wall a step's network to the egress proxy and
157
+ * DNS when its `network:` is restricted and enforced — and is browsing
158
+ * put under that wall (FOL-110 phase 3, browse-egress.ts browseVerdict)?
159
+ * True: a browsing step gets the forward proxy like any other and its
160
+ * browser runs inside the walled sandbox, so the list holds for it.
161
+ * Absent or false: a browsing step browses as before phase 3, said in the
162
+ * trace as not enforced.
163
+ */
164
+ confinesBrowsing?(isolation: string): boolean;
151
165
  /**
152
166
  * An operator setting, by the environment variable that used to hold it
153
167
  * (30 Oct 2026): the platform answers with the operator's value where one
@@ -48,7 +48,7 @@ import { PromptLayers, promptCacheKey } from "./prompt-layers.js";
48
48
  import { loadCatalog, checkModel, clampEffort, catalogCost, findModel, tokenPriceOf } from "./catalog.js";
49
49
  import { resolveSecrets, getSecret, materializeSecrets, secretSites, isClientCertValue, clientCertOf, withoutHeldCerts, isIdentityValue, identityOf } from "./secrets.js";
50
50
  import { resolveNetwork, networkLine, networkEnforceWanted, proxyEnv, siteCovers, EGRESS_CA_ENV } from "./network.js";
51
- import { browseNetworkLine } from "./browse-egress.js";
51
+ import { BROWSER_CONFINED_ENV, browseNetworkLine, browseVerdict } from "./browse-egress.js";
52
52
  import { materializeFileSecrets, cleanupFileSecrets } from "./secret-files.js";
53
53
  import { buildApiTools, secretsUsedByApi } from "./api-tools.js";
54
54
  import { buildA2ATools } from "./a2a-tools.js";
@@ -2827,6 +2827,27 @@ mayDefer) {
2827
2827
  save();
2828
2828
  return;
2829
2829
  }
2830
+ // A step that may browse, on an install with the forward door: held to
2831
+ // its list where the executor walls the step's network, refused when
2832
+ // it names a vendor that list cannot hold, else as before phase 3
2833
+ // (browse-egress.ts browseVerdict, FOL-110).
2834
+ const browses = scriptSpecs.some((sc) => sc.name === "web") && (!web.actions || web.actions.includes("browse"));
2835
+ const browse = browses && lease?.proxy
2836
+ ? browseVerdict({
2837
+ level: network.level,
2838
+ enforce: lease.enforce === true,
2839
+ vendor: clockEnv.FOLDRUN_BROWSER_VENDOR,
2840
+ confines: !!isolation && platform.confinesBrowsing?.(isolation) === true,
2841
+ })
2842
+ : null;
2843
+ if (lease && browse?.kind === "refuse") {
2844
+ push("info", networkLine(network, true));
2845
+ push("error", browse.message);
2846
+ await lease.release();
2847
+ step.status = "failed";
2848
+ save();
2849
+ return;
2850
+ }
2830
2851
  // Serve those jobs while this step runs: each one becomes a step of
2831
2852
  // its own (delegateJob), and the door answers the long-poll with its
2832
2853
  // reply. No proxy, or a platform without the door: not offered — the
@@ -2851,16 +2872,18 @@ mayDefer) {
2851
2872
  // The forward door: every program in the sandbox sends through the
2852
2873
  // proxy, which holds the site list and fills bound secrets. A proxy
2853
2874
  // without the door (an older platform) leaves programs going direct.
2854
- // A step that may browse gets no proxy variables: the browser in it
2855
- // reads HTTPS_PROXY too, and Chromium cannot send credentials written
2856
- // into a proxy URL — every page failed ERR_INVALID_AUTH_CREDENTIALS
2857
- // (14 Oct 2026, the reel posters). Such a step is open by default,
2858
- // and its bound secrets materialise as they did before the door.
2859
- const browses = scriptSpecs.some((sc) => sc.name === "web") && (!web.actions || web.actions.includes("browse"));
2860
- const forward = lease?.proxy && !browses ? lease : null;
2861
- // A browsing step on an install with the door says it is not held to
2862
- // its list yet, and which tier its browser falls in (browse-egress.ts).
2863
- push("info", browses && lease?.proxy ? browseNetworkLine(network, clockEnv.FOLDRUN_BROWSER_VENDOR) : networkLine(network, forward ? forward.enforce === true : null));
2875
+ // A step that may browse gets no proxy variables unless it is held
2876
+ // (browse.kind "hosted"): the browser in it reads HTTPS_PROXY too, and
2877
+ // Chromium cannot send credentials written into a proxy URL — every
2878
+ // page failed ERR_INVALID_AUTH_CREDENTIALS (14 Oct 2026, the reel
2879
+ // posters). A held step's web tool hands the browser the proxy and its
2880
+ // credential as launch options instead (FOLDRUN_BROWSER_CONFINED).
2881
+ // Every other browsing step is open by default, and its bound secrets
2882
+ // materialise as they did before the door.
2883
+ const forward = lease?.proxy && (!browses || browse?.kind === "hosted") ? lease : null;
2884
+ // A browsing step on an install with the door says whether it is held
2885
+ // to its list, and which tier its browser falls in (browse-egress.ts).
2886
+ push("info", browse ? browseNetworkLine(network, clockEnv.FOLDRUN_BROWSER_VENDOR, { hosted: browse.kind === "hosted" }) : networkLine(network, forward ? forward.enforce === true : null));
2864
2887
  const bound = forward ? Object.keys(boundSites).filter((name) => name in liveSecrets) : [];
2865
2888
  for (const name of bound) {
2866
2889
  for (const site of boundSites[name])
@@ -3084,11 +3107,20 @@ mayDefer) {
3084
3107
  // Every program's HTTP(S) through the proxy's forward door, and
3085
3108
  // the CA it signs bound sites with, for the sandbox to trust.
3086
3109
  ...(forward ? proxyEnv(forward.proxy) : {}),
3110
+ // A browsing step held to its list: the web tool gives its
3111
+ // browser the forward door as launch options, refuses what
3112
+ // cannot go through it, and the platform starts no account
3113
+ // browser pod for it (browse-egress.ts, FOL-110 phase 3).
3114
+ ...(browse?.kind === "hosted" ? { [BROWSER_CONFINED_ENV]: "1" } : {}),
3087
3115
  // Only a step with a bound secret has a site the proxy
3088
3116
  // intercepts, so only that step's TLS clients are pointed at a
3089
3117
  // bundle with the egress CA in it; every other step's are as
3090
3118
  // they always were.
3091
- ...(forward?.ca && bound.length ? { [EGRESS_CA_ENV]: Buffer.from(forward.ca).toString("base64") } : {}),
3119
+ // A browser held to its list (browse "hosted") meets the proxy's
3120
+ // leaf on any host a secret is granted to — an api tool's, a web
3121
+ // provider's — not only a bound site, so it is handed the CA
3122
+ // whenever the step has one: the web tool trusts it for Chromium.
3123
+ ...(forward?.ca && (bound.length || (browse?.kind === "hosted" && Object.keys(grant.secrets).length)) ? { [EGRESS_CA_ENV]: Buffer.from(forward.ca).toString("base64") } : {}),
3092
3124
  ...clockEnv,
3093
3125
  // Who is running: the in-process path stamps scripts with these
3094
3126
  // host-side, but a container rebuilds its tools from its own
@@ -372,10 +372,13 @@ export interface AgentInfo {
372
372
  * the default (open when it may fetch or browse the web, else trusted).
373
373
  * `implied` here is its `apis:` hosts; a run also adds its MCP servers',
374
374
  * its web providers' and its bound secrets' sites. */
375
- /** browses: the step may browse — not held to its list yet (FOL-110). */
375
+ /** browses: the step may browse; enforceWanted and browseVendor are what
376
+ * this folder says toward browseVerdict (FOL-110) — the install says the rest. */
376
377
  network: NetworkPolicy & {
377
378
  readsWeb: boolean;
378
379
  browses: boolean;
380
+ enforceWanted: boolean;
381
+ browseVendor: string | null;
379
382
  };
380
383
  /** Tools this agent declares inline rather than in `tools:` — `apis:`,
381
384
  * `scripts:` and `mcpServers:` names — which a limit may also name. */
package/dist/src/store.js CHANGED
@@ -50,7 +50,8 @@ import { parseRemotes, remoteNetworkHosts, A2A_LIMIT_KEY } from "./a2a-remotes.j
50
50
  import { parseBudget, budgetProblem } from "./budget.js";
51
51
  import { timezoneProblem } from "./clock.js";
52
52
  import { parseStepLimits, readLimits } from "./limits.js";
53
- import { networkProblems, resolveNetwork } from "./network.js";
53
+ import { networkEnforceWanted, networkProblems, resolveNetwork } from "./network.js";
54
+ import { browseVendorOf } from "./browse-egress.js";
54
55
  import { webProblems, webWarnings, runnerEngines, webConfig } from "./providers.js";
55
56
  import { actionProblems } from "./web-actions.js";
56
57
  import { languageProblem } from "./language.js";
@@ -1175,9 +1176,14 @@ export function listAgents(tenant, workspace) {
1175
1176
  ],
1176
1177
  }),
1177
1178
  readsWeb,
1178
- // The runner's own test (runner.ts `browses`): such a step gets no
1179
- // forward proxy yet, so its list does not hold (FOL-110).
1179
+ // The runner's own test (runner.ts `browses`). Whether its list holds
1180
+ // for such a step depends on the install too (browse-egress.ts
1181
+ // browseVerdict): the two fields below are this folder's half of it.
1180
1182
  browses: tools.includes("web") && (!actions || actions.includes("browse")),
1183
+ // network_enforce: true in the account's or workspace's AGENTS.md.
1184
+ enforceWanted: networkEnforceWanted(accountFront.network_enforce, workspaceFront.network_enforce),
1185
+ // The vendor its web.browse names, null for foldrun's own browser.
1186
+ browseVendor: browseVendorOf(webConfig(data, { ...accountFront, ...workspaceFront }).raw.browse),
1181
1187
  };
1182
1188
  return {
1183
1189
  network,
@@ -1,7 +1,10 @@
1
1
  /** What became of one trigger firing. `started` is here too: without it the
2
2
  * log answers "why did nothing run" and not "how often does anything",
3
3
  * and the ratio is the whole point of the page. */
4
- export type TriggerOutcome = "started" | "duplicate" | "throttled" | "debounced" | "quarantined" | "paused" | "halted" | "overlap-skipped" | "missed" | "filtered" | "failed";
4
+ export type TriggerOutcome = "started" | "duplicate" | "throttled" | "debounced" | "quarantined" | "paused" | "halted" | "overlap-skipped" | "missed" | "filtered"
5
+ /** The account already had its most runs waiting for their turn
6
+ * (FOL-100, 5 Nov 2026): this one was refused, not lined up. */
7
+ | "queue-full" | "failed";
5
8
  export interface TriggerEvent {
6
9
  t: string;
7
10
  flow: string;
@@ -13,6 +16,13 @@ export interface TriggerEvent {
13
16
  detail?: string;
14
17
  runId?: string;
15
18
  }
19
+ /** A refused start's own code, for rollbackTrigger: a lowercase word an
20
+ * error that carries an HTTP status also carries (`waiting_cap`), never a
21
+ * system errno (`ENOENT`). Undefined for anything else. */
22
+ export declare function refusalCode(err: unknown): string | undefined;
23
+ /** The outcome a start that threw is logged as: `queue-full` for the
24
+ * account's waiting cap, else `failed`. */
25
+ export declare function failedOutcome(code: string | undefined): TriggerOutcome;
16
26
  /** Never throws. A diagnostic that can break a trigger is worse than no
17
27
  * diagnostic: the whole point is to be reading it on the bad morning. */
18
28
  export declare function recordTriggerEvent(tenant: string, workspace: string, event: TriggerEvent): void;
@@ -27,6 +27,18 @@
27
27
  import fs from "node:fs";
28
28
  import path from "node:path";
29
29
  import { workspaceDir } from "./store.js";
30
+ /** A refused start's own code, for rollbackTrigger: a lowercase word an
31
+ * error that carries an HTTP status also carries (`waiting_cap`), never a
32
+ * system errno (`ENOENT`). Undefined for anything else. */
33
+ export function refusalCode(err) {
34
+ const o = err;
35
+ return o && typeof o.status === "number" && typeof o.code === "string" && /^[a-z][a-z0-9_]*$/.test(o.code) ? o.code : undefined;
36
+ }
37
+ /** The outcome a start that threw is logged as: `queue-full` for the
38
+ * account's waiting cap, else `failed`. */
39
+ export function failedOutcome(code) {
40
+ return code === "waiting_cap" ? "queue-full" : "failed";
41
+ }
30
42
  function logFile(tenant, workspace) {
31
43
  return path.join(workspaceDir(tenant, workspace), "trigger-log.jsonl");
32
44
  }
@@ -13,6 +13,7 @@
13
13
  // an agent reads it — the same rule as every other handoff in the format.
14
14
  import crypto from "node:crypto";
15
15
  import { platform } from "./platform.js";
16
+ import { refusalCode } from "./trigger-log.js";
16
17
  import { listFlows, readRun, runVerdict } from "./store.js";
17
18
  import { getSecret, signingSecretShown } from "./secrets.js";
18
19
  /** The last step's result — the same reading runner.ts makes, kept local so
@@ -99,7 +100,7 @@ export async function fireChainedFlows(tenant, workspace, finished) {
99
100
  console.log(`[foldrun] trigger: flow — ${tenant}/${workspace}/${flow.name} started after ${finished.flow} ${finished.status}`);
100
101
  }
101
102
  catch (err) {
102
- await platform.rollbackTrigger(tenant, workspace, flow, { reason: err instanceof Error ? err.message : String(err) });
103
+ await platform.rollbackTrigger(tenant, workspace, flow, { reason: err instanceof Error ? err.message : String(err), code: refusalCode(err) });
103
104
  throw err;
104
105
  }
105
106
  }
@@ -161,7 +162,7 @@ export async function fireStorageTriggers(tenant, workspace, paths, by) {
161
162
  started.push(run.id);
162
163
  }
163
164
  catch (err) {
164
- await platform.rollbackTrigger(tenant, workspace, flow, { reason: err instanceof Error ? err.message : String(err) });
165
+ await platform.rollbackTrigger(tenant, workspace, flow, { reason: err instanceof Error ? err.message : String(err), code: refusalCode(err) });
165
166
  throw err;
166
167
  }
167
168
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@foldrun/core",
3
- "version": "14.5.0",
3
+ "version": "15.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",
@@ -1,26 +1,48 @@
1
1
  // Browsing and `network:` (FOL-110, foldrun-docs/proposals/browse-egress.md).
2
2
  //
3
- // A step that may browse is not held to its `network:` list yet: the runner
4
- // gives it no forward proxy (a browser in the sandbox cannot send credentials
5
- // written into a proxy URL), so the browser — and every other program in that
6
- // step — reaches sites directly. Until the browse service and hosted
7
- // enforcement ship, the trace says so plainly, and says which of the three
8
- // tiers this step's browser will fall in:
3
+ // Three tiers, said in the trace:
9
4
  //
10
5
  // hosted — foldrun's own browser (the account's browser pod, Lightpanda,
11
- // Obscura, a live session): our network boundary will confine it.
6
+ // Obscura, a live session): our network boundary confines it.
12
7
  // vendor — a vendor that takes a customer proxy (Browserbase, Steel,
13
8
  // Hyperbrowser, Browserless): through the egress proxy, enforced
14
- // once that vendor is qualified by our own tests.
9
+ // once that vendor is qualified by our own tests (phase 4).
15
10
  // none — a vendor that always browses through its own network (Bright
16
11
  // Data, ZenRows) or any DevTools address: never enforced; a
17
- // restricted, enforced `network:` will refuse it.
12
+ // restricted, enforced `network:` refuses it.
13
+ //
14
+ // Phase 3 (hosted enforcement) holds a browsing step to its list where the
15
+ // executor can wall the step's network (the k8s tier, with the install's
16
+ // FOLDRUN_BROWSE_ENFORCE=1 — Platform.confinesBrowsing). Such a step gets the
17
+ // forward proxy like any other, so its run pod is `filtered`: it reaches the
18
+ // egress proxy and DNS and nothing else, and the browser runs inside it, in
19
+ // the step's own pod. A client that sets another proxy, a CDP context with
20
+ // its own proxyServer, a curl that ignores HTTPS_PROXY — each finds no route,
21
+ // never a way round the list. Not covered: DNS lookups through the cluster's
22
+ // resolver, which the wall admits and nothing here restricts. browseVerdict
23
+ // says, for one step, which of the three ways it goes; everywhere else (no
24
+ // wall, an open or report-only list) the step browses as it did before
25
+ // phase 3, and the trace says so.
18
26
 
19
- import { findBrowserApi } from "./providers.ts";
20
- import { networkLine, type NetworkPolicy } from "./network.ts";
27
+ import { findBrowserApi, readBrowseSettings, resolveSearch } from "./providers.ts";
28
+ import { networkLine, type NetworkLevel, type NetworkPolicy } from "./network.ts";
21
29
 
22
30
  export type BrowseTier = "hosted" | "vendor" | "none";
23
31
 
32
+ /** Set to "1" in a browsing step held to its list (browseVerdict "hosted"):
33
+ * the web tool gives its browser the forward door as launch options and
34
+ * refuses what cannot go through it; the platform starts no account browser
35
+ * pod for the step (its pod could not reach one, and that pod is not walled). */
36
+ export const BROWSER_CONFINED_ENV = "FOLDRUN_BROWSER_CONFINED";
37
+
38
+ /** The vendor a `web.browse` value names (the runner's FOLDRUN_BROWSER_VENDOR),
39
+ * or null for foldrun's own browser — read the way runner.ts reads it. */
40
+ export function browseVendorOf(browse: unknown): string | null {
41
+ const read = readBrowseSettings(browse);
42
+ const choice = resolveSearch(read.rest, "browse");
43
+ return choice.shape === "direct" && choice.provider ? choice.provider : null;
44
+ }
45
+
24
46
  /** Which tier a step's browser falls in: no vendor (or foldrun) is ours. */
25
47
  export function browseTier(vendor: string | null | undefined): { tier: BrowseTier; title: string } {
26
48
  const name = (vendor ?? "").trim().toLowerCase();
@@ -30,16 +52,65 @@ export function browseTier(vendor: string | null | undefined): { tier: BrowseTie
30
52
  return { tier: api.egress === "proxy" ? "vendor" : "none", title: api.title };
31
53
  }
32
54
 
55
+ /** How one browsing step is held to its `network:` list:
56
+ *
57
+ * legacy — as before phase 3: no forward proxy, the pod keeps the world,
58
+ * and the trace says the list does not hold. An open list, a
59
+ * report-only install, or an executor that cannot wall the
60
+ * step's network.
61
+ * hosted — enforced: the step gets the forward proxy, its pod is walled
62
+ * to the egress proxy and DNS, and foldrun's browser runs in it.
63
+ * refuse — a vendor's browser under a restricted, enforced list on an
64
+ * install that holds browsing: it browses from the vendor's
65
+ * network, which nothing here can hold to the list, so the step
66
+ * is refused before anything connects (decision 4). */
67
+ export type BrowseVerdict =
68
+ | { kind: "legacy" }
69
+ | { kind: "hosted" }
70
+ | { kind: "refuse"; message: string };
71
+
72
+ export function browseVerdict(o: {
73
+ /** The step's resolved level (network.ts). */
74
+ level: NetworkLevel;
75
+ /** Will the proxy refuse a site off the list (lease.enforce)? */
76
+ enforce: boolean;
77
+ /** FOLDRUN_BROWSER_VENDOR: the vendor the agent named, if any. */
78
+ vendor: string | null | undefined;
79
+ /** Can this executor wall the step's network (Platform.confinesBrowsing)? */
80
+ confines: boolean;
81
+ }): BrowseVerdict {
82
+ if (o.level === "open" || !o.enforce || !o.confines) return { kind: "legacy" };
83
+ const { tier, title } = browseTier(o.vendor);
84
+ if (tier === "hosted") return { kind: "hosted" };
85
+ const why =
86
+ tier === "vendor"
87
+ ? `${title} browses from its own network, and foldrun cannot hold it to network: until that vendor is qualified (FOL-110 phase 4)`
88
+ : `${title} always browses through its own network, and nothing can hold it to network:`;
89
+ return {
90
+ kind: "refuse",
91
+ message:
92
+ `browse: refused before it connected — this step's network: ${o.level} is enforced, and ${why}. ` +
93
+ `Drop browse: ${(o.vendor ?? "").trim()} from the agent's web: block to browse with foldrun's own browser, which is held to the list; ` +
94
+ `or, to accept browsing that no list holds for this one agent, give that agent network: open.`,
95
+ };
96
+ }
97
+
33
98
  /** The trace's network line for a step that may browse, on an install with
34
- * an egress proxy: the step's list, and the plain fact that it does not
35
- * hold yet — for the browser or anything else in the step. */
36
- export function browseNetworkLine(policy: NetworkPolicy, vendor: string | null | undefined): string {
37
- const { tier, title } = browseTier(vendor);
99
+ * an egress proxy: the step's list, and whether it holds — `hosted` when
100
+ * browseVerdict put the step under the wall, else the plain fact that it
101
+ * does not hold yet, for the browser or anything else in the step. */
102
+ export function browseNetworkLine(policy: NetworkPolicy, vendor: string | null | undefined, opts: { hosted?: boolean } = {}): string {
38
103
  const what = networkLine(policy, true);
39
- const now = " — not enforced in this step: it may browse, and browsing does not go through the egress proxy yet, so the browser and every other program in this step reach sites directly";
104
+ if (opts.hosted) {
105
+ return `${what} — enforced — hosted: the browser runs inside this step's sandbox, whose network reaches only the egress proxy (which holds the list) and DNS, so a page, a script or a changed proxy setting reaches no site off the list; DNS lookups themselves are not restricted.`;
106
+ }
107
+ const { tier, title } = browseTier(vendor);
108
+ const now = " — not enforced in this step: it may browse, and browsing does not go through the egress proxy here, so the browser and every other program in this step reach sites directly";
40
109
  const later =
41
110
  tier === "hosted"
42
- ? `. Its browser is ${title}: it comes under network: when hosted enforcement ships (FOL-110)`
111
+ ? policy.level === "open"
112
+ ? `. Its browser is ${title}; with an open list there is nothing to hold it to`
113
+ : `. Its browser is ${title}: it is held to network: on an install that confines browsing, with the list enforced (FOL-110)`
43
114
  : tier === "vendor"
44
115
  ? `. Its browser (${title}) browses from the vendor's network: it comes under network: through the egress proxy once that vendor is qualified (FOL-110)`
45
116
  : `. Its browser (${title}) always browses through its own network and cannot be held to network: — a restricted, enforced network: will refuse it (FOL-110)`;
package/src/platform.ts CHANGED
@@ -105,7 +105,9 @@ export interface PlatformHooks {
105
105
  tenant: string,
106
106
  workspace: string,
107
107
  flow: FlowInfo,
108
- opts?: { deliveryKey?: string | null; reason?: string },
108
+ /** `code`: the refusal's own code, when it had one — `waiting_cap`
109
+ * is logged as `queue-full` rather than `failed`. */
110
+ opts?: { deliveryKey?: string | null; reason?: string; code?: string },
109
111
  ): Promise<void>;
110
112
  /** Step executors by FOLDRUN_RUN_ISOLATION value, beyond the `container`
111
113
  * one core ships. The platform adds `k8s`. */
@@ -155,6 +157,16 @@ export interface PlatformHooks {
155
157
  * only where no provider: block of the account's own says otherwise.
156
158
  * Absent: nobody can (a laptop, a self-hosted install). */
157
159
  modelSupply?(tenant: string): SupplyAnswer;
160
+ /**
161
+ * Does this isolation mode wall a step's network to the egress proxy and
162
+ * DNS when its `network:` is restricted and enforced — and is browsing
163
+ * put under that wall (FOL-110 phase 3, browse-egress.ts browseVerdict)?
164
+ * True: a browsing step gets the forward proxy like any other and its
165
+ * browser runs inside the walled sandbox, so the list holds for it.
166
+ * Absent or false: a browsing step browses as before phase 3, said in the
167
+ * trace as not enforced.
168
+ */
169
+ confinesBrowsing?(isolation: string): boolean;
158
170
  /**
159
171
  * An operator setting, by the environment variable that used to hold it
160
172
  * (30 Oct 2026): the platform answers with the operator's value where one
package/src/runner.ts CHANGED
@@ -101,7 +101,7 @@ import { PromptLayers, promptCacheKey } from "./prompt-layers.ts";
101
101
  import { loadCatalog, checkModel, clampEffort, catalogCost, findModel, tokenPriceOf, type Catalog, type TokenPrice } from "./catalog.ts";
102
102
  import { resolveSecrets, getSecret, materializeSecrets, secretSites, isClientCertValue, clientCertOf, withoutHeldCerts, isIdentityValue, identityOf } from "./secrets.ts";
103
103
  import { resolveNetwork, networkLine, networkEnforceWanted, proxyEnv, siteCovers, EGRESS_CA_ENV } from "./network.ts";
104
- import { browseNetworkLine } from "./browse-egress.ts";
104
+ import { BROWSER_CONFINED_ENV, browseNetworkLine, browseVerdict } from "./browse-egress.ts";
105
105
  import { materializeFileSecrets, cleanupFileSecrets } from "./secret-files.ts";
106
106
  import { buildApiTools, secretsUsedByApi } from "./api-tools.ts";
107
107
  import { buildA2ATools } from "./a2a-tools.ts";
@@ -3035,6 +3035,27 @@ async function runStep(
3035
3035
  save();
3036
3036
  return;
3037
3037
  }
3038
+ // A step that may browse, on an install with the forward door: held to
3039
+ // its list where the executor walls the step's network, refused when
3040
+ // it names a vendor that list cannot hold, else as before phase 3
3041
+ // (browse-egress.ts browseVerdict, FOL-110).
3042
+ const browses = scriptSpecs.some((sc) => sc.name === "web") && (!web.actions || web.actions.includes("browse"));
3043
+ const browse = browses && lease?.proxy
3044
+ ? browseVerdict({
3045
+ level: network.level,
3046
+ enforce: lease.enforce === true,
3047
+ vendor: clockEnv.FOLDRUN_BROWSER_VENDOR,
3048
+ confines: !!isolation && platform.confinesBrowsing?.(isolation) === true,
3049
+ })
3050
+ : null;
3051
+ if (lease && browse?.kind === "refuse") {
3052
+ push("info", networkLine(network, true));
3053
+ push("error", browse.message);
3054
+ await lease.release();
3055
+ step.status = "failed";
3056
+ save();
3057
+ return;
3058
+ }
3038
3059
  // Serve those jobs while this step runs: each one becomes a step of
3039
3060
  // its own (delegateJob), and the door answers the long-poll with its
3040
3061
  // reply. No proxy, or a platform without the door: not offered — the
@@ -3060,16 +3081,18 @@ async function runStep(
3060
3081
  // The forward door: every program in the sandbox sends through the
3061
3082
  // proxy, which holds the site list and fills bound secrets. A proxy
3062
3083
  // without the door (an older platform) leaves programs going direct.
3063
- // A step that may browse gets no proxy variables: the browser in it
3064
- // reads HTTPS_PROXY too, and Chromium cannot send credentials written
3065
- // into a proxy URL — every page failed ERR_INVALID_AUTH_CREDENTIALS
3066
- // (14 Oct 2026, the reel posters). Such a step is open by default,
3067
- // and its bound secrets materialise as they did before the door.
3068
- const browses = scriptSpecs.some((sc) => sc.name === "web") && (!web.actions || web.actions.includes("browse"));
3069
- const forward = lease?.proxy && !browses ? lease : null;
3070
- // A browsing step on an install with the door says it is not held to
3071
- // its list yet, and which tier its browser falls in (browse-egress.ts).
3072
- push("info", browses && lease?.proxy ? browseNetworkLine(network, clockEnv.FOLDRUN_BROWSER_VENDOR) : networkLine(network, forward ? forward.enforce === true : null));
3084
+ // A step that may browse gets no proxy variables unless it is held
3085
+ // (browse.kind "hosted"): the browser in it reads HTTPS_PROXY too, and
3086
+ // Chromium cannot send credentials written into a proxy URL — every
3087
+ // page failed ERR_INVALID_AUTH_CREDENTIALS (14 Oct 2026, the reel
3088
+ // posters). A held step's web tool hands the browser the proxy and its
3089
+ // credential as launch options instead (FOLDRUN_BROWSER_CONFINED).
3090
+ // Every other browsing step is open by default, and its bound secrets
3091
+ // materialise as they did before the door.
3092
+ const forward = lease?.proxy && (!browses || browse?.kind === "hosted") ? lease : null;
3093
+ // A browsing step on an install with the door says whether it is held
3094
+ // to its list, and which tier its browser falls in (browse-egress.ts).
3095
+ push("info", browse ? browseNetworkLine(network, clockEnv.FOLDRUN_BROWSER_VENDOR, { hosted: browse.kind === "hosted" }) : networkLine(network, forward ? forward.enforce === true : null));
3073
3096
  const bound = forward ? Object.keys(boundSites).filter((name) => name in liveSecrets) : [];
3074
3097
  for (const name of bound) {
3075
3098
  for (const site of boundSites[name]) addGrant(grant, name, liveSecrets[name], site);
@@ -3297,11 +3320,20 @@ async function runStep(
3297
3320
  // Every program's HTTP(S) through the proxy's forward door, and
3298
3321
  // the CA it signs bound sites with, for the sandbox to trust.
3299
3322
  ...(forward ? proxyEnv(forward.proxy!) : {}),
3323
+ // A browsing step held to its list: the web tool gives its
3324
+ // browser the forward door as launch options, refuses what
3325
+ // cannot go through it, and the platform starts no account
3326
+ // browser pod for it (browse-egress.ts, FOL-110 phase 3).
3327
+ ...(browse?.kind === "hosted" ? { [BROWSER_CONFINED_ENV]: "1" } : {}),
3300
3328
  // Only a step with a bound secret has a site the proxy
3301
3329
  // intercepts, so only that step's TLS clients are pointed at a
3302
3330
  // bundle with the egress CA in it; every other step's are as
3303
3331
  // they always were.
3304
- ...(forward?.ca && bound.length ? { [EGRESS_CA_ENV]: Buffer.from(forward.ca).toString("base64") } : {}),
3332
+ // A browser held to its list (browse "hosted") meets the proxy's
3333
+ // leaf on any host a secret is granted to — an api tool's, a web
3334
+ // provider's — not only a bound site, so it is handed the CA
3335
+ // whenever the step has one: the web tool trusts it for Chromium.
3336
+ ...(forward?.ca && (bound.length || (browse?.kind === "hosted" && Object.keys(grant.secrets).length)) ? { [EGRESS_CA_ENV]: Buffer.from(forward.ca).toString("base64") } : {}),
3305
3337
  ...clockEnv,
3306
3338
  // Who is running: the in-process path stamps scripts with these
3307
3339
  // host-side, but a container rebuilds its tools from its own
package/src/store.ts CHANGED
@@ -55,7 +55,8 @@ import { parseRemotes, remoteNetworkHosts, A2A_LIMIT_KEY, type RemoteSpec } from
55
55
  import { parseBudget, budgetProblem } from "./budget.ts";
56
56
  import { timezoneProblem } from "./clock.ts";
57
57
  import { parseStepLimits, readLimits } from "./limits.ts";
58
- import { networkProblems, resolveNetwork, type NetworkPolicy } from "./network.ts";
58
+ import { networkEnforceWanted, networkProblems, resolveNetwork, type NetworkPolicy } from "./network.ts";
59
+ import { browseVendorOf } from "./browse-egress.ts";
59
60
  import { webProblems, webWarnings, runnerEngines, webConfig } from "./providers.ts";
60
61
  import { actionProblems } from "./web-actions.ts";
61
62
  import { languageProblem } from "./language.ts";
@@ -1050,8 +1051,9 @@ export interface AgentInfo {
1050
1051
  * the default (open when it may fetch or browse the web, else trusted).
1051
1052
  * `implied` here is its `apis:` hosts; a run also adds its MCP servers',
1052
1053
  * its web providers' and its bound secrets' sites. */
1053
- /** browses: the step may browse — not held to its list yet (FOL-110). */
1054
- network: NetworkPolicy & { readsWeb: boolean; browses: boolean };
1054
+ /** browses: the step may browse; enforceWanted and browseVendor are what
1055
+ * this folder says toward browseVerdict (FOL-110) — the install says the rest. */
1056
+ network: NetworkPolicy & { readsWeb: boolean; browses: boolean; enforceWanted: boolean; browseVendor: string | null };
1055
1057
  /** Tools this agent declares inline rather than in `tools:` — `apis:`,
1056
1058
  * `scripts:` and `mcpServers:` names — which a limit may also name. */
1057
1059
  inlineTools: string[];
@@ -1677,9 +1679,14 @@ export function listAgents(tenant: string, workspace: string): AgentInfo[] {
1677
1679
  ],
1678
1680
  }),
1679
1681
  readsWeb,
1680
- // The runner's own test (runner.ts `browses`): such a step gets no
1681
- // forward proxy yet, so its list does not hold (FOL-110).
1682
+ // The runner's own test (runner.ts `browses`). Whether its list holds
1683
+ // for such a step depends on the install too (browse-egress.ts
1684
+ // browseVerdict): the two fields below are this folder's half of it.
1682
1685
  browses: tools.includes("web") && (!actions || actions.includes("browse")),
1686
+ // network_enforce: true in the account's or workspace's AGENTS.md.
1687
+ enforceWanted: networkEnforceWanted(accountFront.network_enforce, workspaceFront.network_enforce),
1688
+ // The vendor its web.browse names, null for foldrun's own browser.
1689
+ browseVendor: browseVendorOf(webConfig(data, { ...accountFront, ...workspaceFront }).raw.browse),
1683
1690
  };
1684
1691
  return {
1685
1692
  network,
@@ -43,6 +43,9 @@ export type TriggerOutcome =
43
43
  | "overlap-skipped"
44
44
  | "missed"
45
45
  | "filtered"
46
+ /** The account already had its most runs waiting for their turn
47
+ * (FOL-100, 5 Nov 2026): this one was refused, not lined up. */
48
+ | "queue-full"
46
49
  | "failed";
47
50
 
48
51
  export interface TriggerEvent {
@@ -57,6 +60,20 @@ export interface TriggerEvent {
57
60
  runId?: string;
58
61
  }
59
62
 
63
+ /** A refused start's own code, for rollbackTrigger: a lowercase word an
64
+ * error that carries an HTTP status also carries (`waiting_cap`), never a
65
+ * system errno (`ENOENT`). Undefined for anything else. */
66
+ export function refusalCode(err: unknown): string | undefined {
67
+ const o = err as { code?: unknown; status?: unknown } | null;
68
+ return o && typeof o.status === "number" && typeof o.code === "string" && /^[a-z][a-z0-9_]*$/.test(o.code) ? o.code : undefined;
69
+ }
70
+
71
+ /** The outcome a start that threw is logged as: `queue-full` for the
72
+ * account's waiting cap, else `failed`. */
73
+ export function failedOutcome(code: string | undefined): TriggerOutcome {
74
+ return code === "waiting_cap" ? "queue-full" : "failed";
75
+ }
76
+
60
77
  function logFile(tenant: string, workspace: string) {
61
78
  return path.join(workspaceDir(tenant, workspace), "trigger-log.jsonl");
62
79
  }
package/src/triggers.ts CHANGED
@@ -14,6 +14,7 @@
14
14
 
15
15
  import crypto from "node:crypto";
16
16
  import { platform } from "./platform.ts";
17
+ import { refusalCode } from "./trigger-log.ts";
17
18
  import { listFlows, readRun, runVerdict, type FlowInfo, type FlowStep, type RunRecord } from "./store.ts";
18
19
  import { getSecret, signingSecretShown } from "./secrets.ts";
19
20
 
@@ -104,7 +105,7 @@ export async function fireChainedFlows(tenant: string, workspace: string, finish
104
105
  started.push(run.id);
105
106
  console.log(`[foldrun] trigger: flow — ${tenant}/${workspace}/${flow.name} started after ${finished.flow} ${finished.status}`);
106
107
  } catch (err) {
107
- await platform.rollbackTrigger(tenant, workspace, flow, { reason: err instanceof Error ? err.message : String(err) });
108
+ await platform.rollbackTrigger(tenant, workspace, flow, { reason: err instanceof Error ? err.message : String(err), code: refusalCode(err) });
108
109
  throw err;
109
110
  }
110
111
  } catch (err) {
@@ -166,7 +167,7 @@ export async function fireStorageTriggers(
166
167
  ]);
167
168
  started.push(run.id);
168
169
  } catch (err) {
169
- await platform.rollbackTrigger(tenant, workspace, flow, { reason: err instanceof Error ? err.message : String(err) });
170
+ await platform.rollbackTrigger(tenant, workspace, flow, { reason: err instanceof Error ? err.message : String(err), code: refusalCode(err) });
170
171
  throw err;
171
172
  }
172
173
  } catch (err) {