opencode-fs-plugin 1.10.1 → 1.11.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.
package/README.md CHANGED
@@ -139,26 +139,38 @@ work, fan out with `Promise.all` over `tools.fs.*` (or one multi-path call).
139
139
  }
140
140
  ```
141
141
 
142
- The workspace (project) is read/write/exec, but **network and external paths are
143
- denied by default**. There are no per-call grants: when the sandbox blocks a
144
- path or a socket, `fs.exec` asks the matching permission and retries the run.
142
+ The workspace (project) is read/write/exec. **Network is proxy-only by
143
+ default**: every run gets its own egress proxy, no direct route, and only
144
+ allowlisted hosts are reachable. Pre-approve hosts in the plugin options:
145
145
 
146
- - blocked path → `external_directory` for its containing directory; the sandbox
147
- then grants read/write there. A missing or `***`-redacted path resolves to the
148
- nearest existing ancestor.
149
- - blocked socket → `fs_exec_network`
146
+ ```jsonc
147
+ {
148
+ "options": {
149
+ "execNetworkAllowlist": ["registry.npmjs.org", "*.npmjs.org"]
150
+ }
151
+ }
152
+ ```
153
+
154
+ A host the proxy refuses asks `fs_exec_network` with that host, and the run
155
+ retries with it added. `execNetworkMode: "ip"` opts into all-IP networking after
156
+ the same approval instead. External paths are separate: a blocked path asks
157
+ `external_directory` for its containing directory (or the nearest existing
158
+ ancestor), and the sandbox grants read/write there.
150
159
 
151
160
  The decision comes from your `opencode.jsonc` rules (`ask`, `allow`, `deny`), the
152
- same as every other tool. If a path is still blocked after approval, the result
161
+ same as every other tool. If a path stays blocked after approval, the result
153
162
  reports `violations` and a `hint`. `fs.exec` also kills every process it started
154
163
  when the run ends, including detached descendants.
155
164
 
156
- With network enabled, the policy also opens the resolver sockets used by
157
- systemd-resolved, nscd, and SSSD (`/run/systemd/resolve`, `/run/nscd`,
158
- `/var/lib/sss/pipes`), so DNS works across common Linux distributions. Plain
159
- UDP DNS needs none of them; other Unix sockets stay blocked. On kernels where
160
- procage cannot scope Unix sockets (T2 below Landlock ABI 9), the policy drops
161
- them via `no-unix-sockets`; DNS then works only through a plain UDP resolver.
165
+ Proxy mode needs Linux T1 (user namespaces) or macOS. On Linux T2 there is no
166
+ network namespace, so `fs.exec` falls back to all-IP: a socket denial asks
167
+ `fs_exec_network` and retries with `ip`. In `ip` mode the policy also opens the
168
+ resolver sockets used by systemd-resolved, nscd, and SSSD
169
+ (`/run/systemd/resolve`, `/run/nscd`, `/var/lib/sss/pipes`), so DNS works across
170
+ common Linux distributions. Plain UDP DNS needs none of them; other Unix sockets
171
+ stay blocked. On kernels where procage cannot scope Unix sockets (T2 below
172
+ Landlock ABI 9), the policy drops them via `no-unix-sockets`; DNS then works only
173
+ through a plain UDP resolver.
162
174
 
163
175
  ```js
164
176
  await tools.fs.exec({ command: "npm", args: ["install"], timeoutMs: 300000 })
@@ -268,18 +280,18 @@ Add the registry package directly to the plugin list:
268
280
 
269
281
  ```jsonc
270
282
  {
271
- "plugins": ["opencode-fs-plugin@1.10.1"]
283
+ "plugins": ["opencode-fs-plugin@1.11.0"]
272
284
  }
273
285
  ```
274
286
 
275
- `opencode plugin add opencode-fs-plugin@1.10.1` installs it and writes the config
287
+ `opencode plugin add opencode-fs-plugin@1.11.0` installs it and writes the config
276
288
  entry. A bare `opencode-fs-plugin` follows the `latest` tag.
277
289
 
278
290
  OpenCode manages the package under its cache, so the path is not stable. If you
279
291
  also want the packaged skill, install it into a project instead:
280
292
 
281
293
  ```bash
282
- npm install opencode-fs-plugin@1.10.1
294
+ npm install opencode-fs-plugin@1.11.0
283
295
  ```
284
296
 
285
297
  ```jsonc
@@ -294,7 +306,7 @@ npm install opencode-fs-plugin@1.10.1
294
306
  Download the release tarball, then install it as a normal npm package:
295
307
 
296
308
  ```bash
297
- VERSION=1.10.1
309
+ VERSION=1.11.0
298
310
  curl -L -o "opencode-fs-plugin-${VERSION}.tgz" \
299
311
  "https://github.com/masterjg/opencode-fs-plugin/releases/download/v${VERSION}/opencode-fs-plugin-${VERSION}.tgz"
300
312
  npm install "./opencode-fs-plugin-${VERSION}.tgz"
@@ -323,20 +335,20 @@ OpenCode installs it from Git:
323
335
 
324
336
  ```jsonc
325
337
  {
326
- "plugins": ["github:masterjg/opencode-fs-plugin#v1.10.1"]
338
+ "plugins": ["github:masterjg/opencode-fs-plugin#v1.11.0"]
327
339
  }
328
340
  ```
329
341
 
330
- `opencode plugin add 'github:masterjg/opencode-fs-plugin#v1.10.1'` installs the
342
+ `opencode plugin add 'github:masterjg/opencode-fs-plugin#v1.11.0'` installs the
331
343
  same spec and writes the config entry. The equivalent full URL is
332
- `git+https://github.com/masterjg/opencode-fs-plugin.git#v1.10.1`. A tag is
344
+ `git+https://github.com/masterjg/opencode-fs-plugin.git#v1.11.0`. A tag is
333
345
  checked for updates; use a full commit hash to pin it.
334
346
 
335
347
  Git plugins are installed under OpenCode's cache, so their package path is not
336
348
  stable. If you also want the packaged skill, install with npm instead:
337
349
 
338
350
  ```bash
339
- npm install "github:masterjg/opencode-fs-plugin#v1.10.1"
351
+ npm install "github:masterjg/opencode-fs-plugin#v1.11.0"
340
352
  ```
341
353
 
342
354
  Then use `./node_modules/opencode-fs-plugin` in `plugins` and
@@ -395,7 +407,8 @@ external targets first require `external_directory` on the absolute boundary.
395
407
  `allow always` persists the same patterns as the built-in tools.
396
408
 
397
409
  `fs.exec` asserts `fs_exec` for the run, then asks `external_directory` for any
398
- blocked path and `fs_exec_network` for blocked sockets before retrying:
410
+ blocked path and `fs_exec_network` for a refused host (the resource is the host,
411
+ or `*` in ip mode) before retrying:
399
412
 
400
413
  ```jsonc
401
414
  {
package/SPEC.md CHANGED
@@ -86,21 +86,28 @@ Aliases are accepted only where noted: `path` for one `paths` element (`stat`,
86
86
  Default: `npm`, `npx`, `uv`, `uvx`, `pip`, `pip3`. Override with the plugin
87
87
  option `execAllowlist`; an empty list disables execution.
88
88
  - The policy is procage `agent_workspace` v3: the project is read/write/exec.
89
- Network and external paths are denied by default; there are no per-call
90
- grants.
91
- - When network is enabled, the policy is `ip` (IPv4/IPv6) plus the resolver
92
- sockets used by systemd-resolved, nscd, and SSSD. Plain UDP DNS needs none;
93
- other Unix sockets stay blocked. Landlock ignores paths absent on the host.
94
- On T2 below Landlock ABI 9 the sockets cannot be scoped, so the
95
- `no-unix-sockets` relaxation drops them and only UDP DNS remains.
96
- - Denied access is handled by asserting the configured permission and retrying,
97
- bounded to six attempts: a blocked path asks `external_directory` on its
98
- containing directory (or the nearest existing ancestor for a missing or
99
- redacted path), a blocked socket asks `fs_exec_network`. The `allow`/`ask`/`deny`
100
- decision comes from `opencode.jsonc`, not from the tool call.
89
+ Network is proxy-only and external paths are denied by default; there are no
90
+ per-call grants.
91
+ - Network is proxy-only by default: the cage gets a procage proxy whose
92
+ allowlist is the configured `execNetworkAllowlist` plus the hosts approved
93
+ in this run. A refused host asks `fs_exec_network` with the host as the
94
+ resource, then the run retries with it added. The decision comes from
95
+ `opencode.jsonc`.
96
+ - `execNetworkMode: "ip"` opts into all-IP networking after `fs_exec_network`
97
+ approval. In `ip` mode the policy also opens the resolver sockets used by
98
+ systemd-resolved, nscd, and SSSD. Plain UDP DNS needs none; other Unix
99
+ sockets stay blocked. Landlock ignores paths absent on the host. On T2 below
100
+ Landlock ABI 9 the sockets cannot be scoped, so `no-unix-sockets` drops them
101
+ and only UDP DNS remains.
102
+ - Proxy mode needs Linux T1 or macOS. On T2 the cage fails with the `net-proxy`
103
+ gap; `fs.exec` retries in `ip` mode and asks on a socket denial.
104
+ - Denied paths ask `external_directory` on their containing directory (or the
105
+ nearest existing ancestor for a missing or redacted path). Access handling is
106
+ bounded to twelve attempts.
101
107
  - If a path or socket stays blocked after approval, the result reports
102
108
  `violations` plus a `hint`; stderr containing EACCES/EPERM/EROFS marks
103
- `sandboxBlocked`.
109
+ `sandboxBlocked`. Results carry `network`, `networkMode`, `networkHosts`, and
110
+ `externalPaths`.
104
111
  - `args` are passed verbatim. `cwd` resolves inside the sandbox and asserts
105
112
  `external_directory` when it leaves the project; the action is `fs_exec`.
106
113
  - Timeout defaults to 120000 ms, capped at 600000. Procage ends the run and kills
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-fs-plugin",
3
- "version": "1.10.1",
3
+ "version": "1.11.0",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "node": ">=22.12"
@@ -36,7 +36,7 @@
36
36
  "@sinclair/typebox": "^0.34.52",
37
37
  "diff": "^9.0.0",
38
38
  "picomatch": "^4.0.7",
39
- "procage": "^0.8.0",
39
+ "procage": "https://github.com/masterjg/procage/releases/download/node-proxy-v1/procage-0.8.0.tgz",
40
40
  "tar-stream": "^3.2.2",
41
41
  "yauzl": "^3.4.0",
42
42
  "yazl": "^3.3.1"
@@ -156,18 +156,20 @@ override it with the fs plugin option `execAllowlist` in `opencode.jsonc`:
156
156
  { "package": "./repos/opencode-fs-plugin", "options": { "execAllowlist": ["npm", "uv"] } }
157
157
  ```
158
158
 
159
- The project is read/write/exec. **Network and external paths are denied by
160
- default, and there are no per-call grants.** When the sandbox blocks something,
161
- `fs.exec` asks `external_directory` for the path or `fs_exec_network` for a
162
- socket, then retries; the decision comes from `opencode.jsonc`:
159
+ The project is read/write/exec. **Network is proxy-only by default, and there
160
+ are no per-call grants.** The run gets its own egress proxy with no direct
161
+ route; a refused host asks `fs_exec_network` with the host and the run retries
162
+ with it added. Pre-approve hosts with `execNetworkAllowlist`; set
163
+ `execNetworkMode: "ip"` to opt into all-IP after approval instead. On Linux T2
164
+ (no network namespace) the run falls back to `ip`.
163
165
 
164
166
  ```js
165
167
  await tools.fs.exec({ command: "npm", args: ["install"], timeoutMs: 300000 })
166
168
  ```
167
169
 
168
- Denied access returns `violations` and a `hint`; approval covers the denied
169
- path's containing directory (or nearest existing ancestor), and a path still
170
- blocked after approval is reported. With network approved, DNS works through the
170
+ Denied paths ask `external_directory` and approval covers the denied path's
171
+ containing directory (or nearest existing ancestor). Denied access returns
172
+ `violations` and a `hint`. In `ip` mode DNS works through the
171
173
  systemd-resolved, nscd, or SSSD sockets where the kernel can scope them; other
172
174
  Unix sockets stay blocked and plain UDP DNS works everywhere.
173
175
  `command` is a bare name, `args` are literal, and `cwd` is sandboxed. Direct
@@ -419,8 +421,8 @@ await tools.fs.http_request({
419
421
  - Linux only; there is no Windows branch.
420
422
  - `fs.sed` supports `s<delim>pattern<delim>replacement<delim>flags` with `g`,
421
423
  `i` and `p`. It is not a full sed interpreter.
422
- - `fs.exec` requires procage: Linux x64/arm64, glibc 2.28+, Node 22.12+. Network
423
- and external paths are denied until approved.
424
+ - `fs.exec` requires procage: Linux x64/arm64, glibc 2.28+, Node 22.12+.
425
+ Network is proxy-only by default; external paths are denied until approved.
424
426
  - `fs.find` has no arbitrary `-exec`; use `action: "delete"`/`"trash"` for the
425
427
  common cleanup case, or `fs.rm`/`fs.trash` separately.
426
428
  - No `xz`, `zstd`, `7z`, `rar`, `chattr`, ACLs, xattrs, or `rsync`.
@@ -475,9 +477,9 @@ in agent rules. `fs.pipe` asserts each stage's action; a denied stage cannot be
475
477
  hidden inside a pipeline. Do not work around a denied tool with shell.
476
478
 
477
479
  `fs_exec` runs only exact allowlisted names in a procage sandbox. It asserts
478
- `fs_exec`, then asks `external_directory` for a blocked path or `fs_exec_network`
479
- for a blocked socket and retries; there are no per-call grants. There is no
480
- shell.
480
+ `fs_exec`, asks `external_directory` for a blocked path, and asks
481
+ `fs_exec_network` with the refused host (or `*` in `ip` mode), then retries.
482
+ There are no per-call grants and no shell.
481
483
 
482
484
  `fs_http_request` is allowed by default, like `fetch`. Its resource is the
483
485
  request host; rules can allow one host and ask or deny the rest. Each redirect
package/src/core/types.ts CHANGED
@@ -32,6 +32,10 @@ export interface RunContext {
32
32
  readonly tmpdir: string;
33
33
  readonly maxOutputBytes: number;
34
34
  readonly execAllowlist: readonly string[];
35
+ /** `proxy` forces egress through the run's allowlist proxy; `ip` is all-IP. */
36
+ readonly execNetworkMode: "proxy" | "ip";
37
+ /** Hosts pre-approved for every `fs.exec` proxy run. */
38
+ readonly execNetworkAllowlist: readonly string[];
35
39
  }
36
40
 
37
41
  export interface ToolSpec<I> {
package/src/index.ts CHANGED
@@ -30,7 +30,12 @@ import { diffTool } from "./tools/diff.js";
30
30
  import { duTool } from "./tools/du.js";
31
31
  import { fileTool } from "./tools/file.js";
32
32
  import { findTool } from "./tools/find.js";
33
- import { execTool, normalizeExecAllowlist } from "./tools/exec.js";
33
+ import {
34
+ execTool,
35
+ normalizeExecAllowlist,
36
+ normalizeExecNetworkAllowlist,
37
+ normalizeExecNetworkMode,
38
+ } from "./tools/exec.js";
34
39
  import { findmntTool } from "./tools/findmnt.js";
35
40
  import { foldTool } from "./tools/fold.js";
36
41
  import { grepTool } from "./tools/grep.js";
@@ -199,6 +204,8 @@ export default Plugin.define({
199
204
  typeof ctx.options?.concurrency === "number" ? ctx.options.concurrency : undefined,
200
205
  );
201
206
  const execAllowlist = normalizeExecAllowlist(ctx.options?.execAllowlist);
207
+ const execNetworkMode = normalizeExecNetworkMode(ctx.options?.execNetworkMode);
208
+ const execNetworkAllowlist = normalizeExecNetworkAllowlist(ctx.options?.execNetworkAllowlist);
202
209
  const maxOutputBytes =
203
210
  typeof ctx.options?.maxOutputBytes === "number" && ctx.options.maxOutputBytes > 0
204
211
  ? Math.trunc(ctx.options.maxOutputBytes)
@@ -252,6 +259,8 @@ export default Plugin.define({
252
259
  tmpdir: os.tmpdir(),
253
260
  maxOutputBytes,
254
261
  execAllowlist,
262
+ execNetworkMode,
263
+ execNetworkAllowlist,
255
264
  },
256
265
  parsed,
257
266
  {},
package/src/tools/exec.ts CHANGED
@@ -7,7 +7,7 @@ import * as fs from "node:fs/promises";
7
7
  import { constants as fsConstants } from "node:fs";
8
8
  import * as path from "node:path";
9
9
  import { Type, type Static } from "@sinclair/typebox";
10
- import type { Violation } from "procage";
10
+ import type { Relaxation, Violation } from "procage";
11
11
  import { FsError } from "../core/errors.js";
12
12
  import { collect } from "../core/stream.js";
13
13
  import { textResult, type RunContext, type ToolSpec } from "../core/types.js";
@@ -62,10 +62,86 @@ export interface PolicyDocument {
62
62
  */
63
63
  export const RESOLVER_SOCKETS = ["/run/systemd/resolve", "/run/nscd", "/var/lib/sss/pipes"] as const;
64
64
 
65
- /** Set the network mode, plus the resolver sockets it needs. */
66
- export function applyNetworkPolicy(doc: PolicyDocument, network: boolean): void {
67
- doc.net = network ? "ip" : "none";
68
- if (network) doc.ipc.unix_sockets = [...RESOLVER_SOCKETS];
65
+ /** The proxy allowlist must not be empty; this name never resolves. */
66
+ export const PROXY_SENTINEL = "procage.invalid";
67
+
68
+ export type ExecNetworkMode = "proxy" | "ip";
69
+
70
+ export function normalizeExecNetworkMode(value: unknown): ExecNetworkMode {
71
+ if (value === undefined) return "proxy";
72
+ if (value === "proxy" || value === "ip") return value;
73
+ throw new FsError('execNetworkMode must be "proxy" or "ip".', "invalid");
74
+ }
75
+
76
+ export function normalizeExecNetworkAllowlist(value: unknown): readonly string[] {
77
+ if (value === undefined) return [];
78
+ if (!Array.isArray(value)) {
79
+ throw new FsError("execNetworkAllowlist must be an array of hosts.", "invalid");
80
+ }
81
+ const hosts: string[] = [];
82
+ for (const entry of value) {
83
+ if (typeof entry !== "string" || entry.trim() === "") {
84
+ throw new FsError("execNetworkAllowlist entries must be non-empty strings.", "invalid");
85
+ }
86
+ hosts.push(entry.trim());
87
+ }
88
+ return [...new Set(hosts)];
89
+ }
90
+
91
+ /** `ip` adds all-IP networking; both modes get the local resolver sockets. */
92
+ export function applyNetworkPolicy(doc: PolicyDocument, mode: ExecNetworkMode): void {
93
+ doc.ipc.unix_sockets = [...RESOLVER_SOCKETS];
94
+ if (mode === "ip") doc.net = "ip";
95
+ }
96
+
97
+ /** A host the run's proxy refused. */
98
+ export interface ProxyHost {
99
+ /** Host without a port, for the permission resource. */
100
+ host: string;
101
+ /** `host:port`, for the allowlist entry. */
102
+ entry: string;
103
+ }
104
+
105
+ /** The refused host in a proxy violation, if this violation is one. */
106
+ export function proxyHostOf(violation: Violation): ProxyHost | undefined {
107
+ if (violation.operation !== "network-outbound") return undefined;
108
+ const match = /^(\[[^\]]+\]|[^\s:]+)(?::(\d+))? \(not on the allowlist\)$/.exec(violation.target ?? "");
109
+ if (match === null) return undefined;
110
+ const host = match[1]!;
111
+ return { host, entry: match[2] === undefined ? host : `${host}:${match[2]}` };
112
+ }
113
+
114
+ /**
115
+ * Ask `fs_exec_network` for every host the run's proxy refused, and add the
116
+ * approved ones to `hosts`. Returns whether the list grew.
117
+ */
118
+ export async function approveProxyHosts(
119
+ ctx: Pick<RunContext, "permissionFor">,
120
+ outcome: ExecOutcome,
121
+ hosts: string[],
122
+ ): Promise<boolean> {
123
+ if (outcome.networkMode !== "proxy") return false;
124
+ let added = false;
125
+ for (const violation of outcome.violations) {
126
+ const host = proxyHostOf(violation);
127
+ if (host === undefined || hosts.includes(host.entry)) continue;
128
+ await ctx.permissionFor("fs_exec_network").assertTrusted([host.host]);
129
+ hosts.push(host.entry);
130
+ added = true;
131
+ }
132
+ return added;
133
+ }
134
+
135
+ /** Whether the host cannot keep a run to a proxy-only route (Linux T2). */
136
+ export function isProxyGap(error: unknown, api: typeof import("procage")): boolean {
137
+ return error instanceof api.CapabilityGapError && error.gaps.some((gap) => gap.construct === "net-proxy");
138
+ }
139
+
140
+ /** Why a blocked run failed, and what to do about it. */
141
+ export function blockedHint(mode: ExecNetworkMode): string {
142
+ return mode === "proxy"
143
+ ? 'The run\'s network is proxy-only and a program tried to bypass it. Use a proxy-aware client, or set execNetworkMode to "ip".'
144
+ : "The sandbox denied an external path or network access. Approve the path or network in the permission prompt and retry.";
69
145
  }
70
146
 
71
147
  export interface ExecOutcome {
@@ -77,6 +153,8 @@ export interface ExecOutcome {
77
153
  aborted: boolean;
78
154
  stdoutTruncated: boolean;
79
155
  stderrTruncated: boolean;
156
+ /** The mode the sandbox actually ran: proxy may fall back to ip. */
157
+ networkMode: ExecNetworkMode;
80
158
  violations: Violation[];
81
159
  }
82
160
 
@@ -91,8 +169,8 @@ export const execTool: ToolSpec<Input> = {
91
169
  name: "exec",
92
170
  description:
93
171
  "Run an allowlisted executable in a procage sandbox without a shell. Direct calls return JSON; " +
94
- "pipe stages pass raw stdout. Default allowlist: npm, npx, uv, uvx, pip, pip3. Network and external " +
95
- "paths are denied until approved.",
172
+ "pipe stages pass raw stdout. Default allowlist: npm, npx, uv, uvx, pip, pip3. Network is forced " +
173
+ "through the run's allowlist proxy by default; a refused host asks fs_exec_network.",
96
174
  schema: Schema,
97
175
  pipeable: "filter",
98
176
  mutates: true,
@@ -122,35 +200,37 @@ export const execTool: ToolSpec<Input> = {
122
200
  const inputData = io.stdin === undefined
123
201
  ? input.stdin === undefined ? undefined : Buffer.from(input.stdin)
124
202
  : await collect(io.stdin);
125
- let networkAllowed = false;
203
+ let networkMode = ctx.execNetworkMode;
204
+ const proxyHosts = [...ctx.execNetworkAllowlist];
205
+ let ipNetwork = false;
126
206
  const approved: Array<{ full: string }> = [];
127
207
  let outcome: ExecOutcome | undefined;
128
208
 
129
- for (let attempt = 0; attempt < 6; attempt++) {
209
+ for (let attempt = 0; attempt < 12; attempt++) {
130
210
  outcome = await runCaged(ctx, {
131
211
  command,
132
212
  executable,
133
213
  args,
134
214
  cwd: cwdTarget.full,
135
215
  timeoutMs: input.timeoutMs ?? 120_000,
136
- network: networkAllowed,
216
+ networkMode,
217
+ proxyHosts,
218
+ ipNetwork,
137
219
  allowed: approved,
138
220
  tempDir,
139
221
  input: inputData,
140
222
  });
223
+ networkMode = outcome.networkMode;
141
224
 
142
- const networkDenied = !networkAllowed && detectsNetworkDenial(outcome);
143
- const deniedPaths = discoverExternalPaths(ctx, outcome)
144
- .filter((candidate) => !approved.some((entry) => entry.full === candidate));
145
- if (!networkDenied && deniedPaths.length === 0) break;
146
-
147
- if (networkDenied) {
225
+ if (networkMode === "ip" && !ipNetwork && detectsNetworkDenial(outcome)) {
148
226
  await ctx.permissionFor("fs_exec_network").assert([]);
149
- networkAllowed = true;
227
+ ipNetwork = true;
150
228
  continue;
151
229
  }
152
230
 
153
- let added = false;
231
+ let added = await approveProxyHosts(ctx, outcome, proxyHosts);
232
+ const deniedPaths = discoverExternalPaths(ctx, outcome)
233
+ .filter((candidate) => !approved.some((entry) => entry.full === candidate));
154
234
  for (const candidate of deniedPaths) {
155
235
  const target = await existingBoundary(ctx, candidate);
156
236
  if (target === undefined) continue;
@@ -181,7 +261,9 @@ export const execTool: ToolSpec<Input> = {
181
261
  stderrTruncated: outcome.stderrTruncated,
182
262
  sandboxBlocked: isSandboxBlocked(outcome),
183
263
  violations: outcome.violations.length,
184
- network: networkAllowed,
264
+ network: networkMode === "proxy" || ipNetwork,
265
+ networkMode,
266
+ networkHosts: proxyHosts,
185
267
  externalPaths: approved.map((entry) => entry.full),
186
268
  };
187
269
  if (io.piped === true) {
@@ -198,12 +280,7 @@ export const execTool: ToolSpec<Input> = {
198
280
  stdout: outcome.stdout.toString("utf8"),
199
281
  stderr: outcome.stderr.toString("utf8"),
200
282
  violations: outcome.violations,
201
- ...(sandboxBlocked
202
- ? {
203
- hint:
204
- "The sandbox denied an external path or network access. Approve the path or network in the permission prompt and retry.",
205
- }
206
- : {}),
283
+ ...(sandboxBlocked ? { hint: blockedHint(networkMode) } : {}),
207
284
  };
208
285
  return textResult(JSON.stringify(body, null, 2), metadata, outcome.exitCode === 0 ? 0 : 1);
209
286
  } finally {
@@ -223,7 +300,9 @@ interface CagedInput {
223
300
  args: string[];
224
301
  cwd: string;
225
302
  timeoutMs: number;
226
- network: boolean;
303
+ networkMode: ExecNetworkMode;
304
+ proxyHosts: readonly string[];
305
+ ipNetwork: boolean;
227
306
  allowed: Array<{ full: string }>;
228
307
  tempDir: string;
229
308
  input: Buffer | undefined;
@@ -239,7 +318,7 @@ async function runCaged(ctx: RunContext, input: CagedInput): Promise<ExecOutcome
239
318
  }
240
319
 
241
320
  const doc = api.Policy.preset("agent_workspace", 3, { workspace: ctx.sandbox.root }).toJSON() as PolicyDocument;
242
- applyNetworkPolicy(doc, input.network);
321
+ applyNetworkPolicy(doc, input.networkMode === "ip" && !input.ipNetwork ? "proxy" : input.networkMode);
243
322
  addRule(doc, "exec", path.dirname(input.executable.path));
244
323
  addRule(doc, "exec", path.dirname(input.executable.real));
245
324
  addRule(doc, "exec", path.dirname(process.execPath));
@@ -259,16 +338,25 @@ async function runCaged(ctx: RunContext, input: CagedInput): Promise<ExecOutcome
259
338
  addRule(doc, "write", input.cwd);
260
339
  for (const allowed of input.allowed) addRule(doc, "write", allowed.full);
261
340
 
341
+ const cageOptions = {
342
+ violations: true,
343
+ acceptSpawnSnapshot: true,
344
+ relax: ["waive:trust-handoff", "signals-same-user", "no-unix-sockets"] as Relaxation[],
345
+ ...(input.networkMode === "proxy"
346
+ ? { proxy: { allowlist: input.proxyHosts.length === 0 ? [PROXY_SENTINEL] : [...input.proxyHosts] } }
347
+ : {}),
348
+ };
349
+
262
350
  let cage: InstanceType<typeof api.Cage>;
263
351
  let policy: ReturnType<typeof api.Policy.fromJSON>;
264
352
  try {
265
353
  policy = api.Policy.fromJSON(doc);
266
- cage = new api.Cage(policy, {
267
- violations: true,
268
- acceptSpawnSnapshot: true,
269
- relax: ["waive:trust-handoff", "signals-same-user", "no-unix-sockets"],
270
- });
354
+ cage = new api.Cage(policy, cageOptions);
271
355
  } catch (error) {
356
+ /* v8 ignore next 3 */
357
+ if (input.networkMode === "proxy" && isProxyGap(error, api)) {
358
+ return runCaged(ctx, { ...input, networkMode: "ip" });
359
+ }
272
360
  /* v8 ignore next */
273
361
  throw new FsError(`exec policy rejected: ${String(error)}`, "unsupported");
274
362
  }
@@ -310,10 +398,11 @@ async function runCaged(ctx: RunContext, input: CagedInput): Promise<ExecOutcome
310
398
  aborted,
311
399
  stdoutTruncated: stdout.truncated,
312
400
  stderrTruncated: stderr.truncated,
401
+ networkMode: input.networkMode,
313
402
  violations,
314
403
  };
315
404
  } catch (error) {
316
- /* v8 ignore next 14 */
405
+ /* v8 ignore next 15 */
317
406
  if (aborted || ctx.signal.aborted) {
318
407
  return {
319
408
  stdout: Buffer.alloc(0),
@@ -324,6 +413,7 @@ async function runCaged(ctx: RunContext, input: CagedInput): Promise<ExecOutcome
324
413
  aborted: true,
325
414
  stdoutTruncated: false,
326
415
  stderrTruncated: false,
416
+ networkMode: input.networkMode,
327
417
  violations: [],
328
418
  };
329
419
  }
@@ -360,6 +450,7 @@ function addRule(doc: PolicyDocument, access: string, target: string): void {
360
450
 
361
451
  export function filterViolations(violations: readonly Violation[]): Violation[] {
362
452
  return violations.filter((violation) => {
453
+ if (proxyHostOf(violation) !== undefined) return true;
363
454
  if (violation.target?.startsWith("/")) return true;
364
455
  return /AF_INET|AF_INET6/.test(violation.target ?? "");
365
456
  });