@capybara-hq/device 0.1.0-rc.8 → 0.1.0-rc.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/README.md +90 -179
  2. package/dist/api.d.ts +5 -0
  3. package/dist/args.d.ts +7 -2
  4. package/dist/args.js +33 -16
  5. package/dist/cli.d.ts +7 -5
  6. package/dist/cli.js +20 -31
  7. package/dist/client.d.ts +0 -2
  8. package/dist/client.js +9 -10
  9. package/dist/command-log.d.ts +3 -5
  10. package/dist/commands/login.js +55 -1
  11. package/dist/commands/mode.d.ts +52 -0
  12. package/dist/commands/mode.js +108 -0
  13. package/dist/commands/policy.d.ts +11 -65
  14. package/dist/commands/policy.js +62 -249
  15. package/dist/commands/start.d.ts +2 -2
  16. package/dist/commands/start.js +14 -6
  17. package/dist/commands/status.js +11 -3
  18. package/dist/exec/docker.d.ts +22 -30
  19. package/dist/exec/docker.js +81 -69
  20. package/dist/exec/fs-helper.d.ts +13 -8
  21. package/dist/exec/fs-helper.js +30 -12
  22. package/dist/exec/host.d.ts +8 -8
  23. package/dist/exec/host.js +9 -9
  24. package/dist/exec/os.d.ts +36 -69
  25. package/dist/exec/os.js +65 -159
  26. package/dist/exec/sandbox-messages.d.ts +14 -0
  27. package/dist/exec/sandbox-messages.js +21 -0
  28. package/dist/exec/shared.d.ts +21 -36
  29. package/dist/exec/shared.js +30 -164
  30. package/dist/exec/switch.d.ts +38 -55
  31. package/dist/exec/switch.js +58 -108
  32. package/dist/exec/types.d.ts +8 -18
  33. package/dist/index.d.ts +1 -1
  34. package/dist/network.d.ts +7 -7
  35. package/dist/network.js +11 -18
  36. package/dist/policy-store.d.ts +7 -8
  37. package/dist/policy-store.js +11 -15
  38. package/dist/policy.d.ts +25 -100
  39. package/dist/policy.js +44 -146
  40. package/dist/server-ops.d.ts +15 -35
  41. package/dist/server-ops.js +36 -117
  42. package/dist/state.d.ts +15 -16
  43. package/dist/state.js +38 -36
  44. package/package.json +2 -2
  45. package/dist/proxy-guard.d.ts +0 -58
  46. package/dist/proxy-guard.js +0 -137
@@ -1,74 +1,15 @@
1
- import { isSandboxTier, validateAllowHost } from "@capybara-hq/plugin-sdk";
2
- import { tierFacts } from "../policy.js";
1
+ import { validateAllowHost } from "@capybara-hq/plugin-sdk";
3
2
  import { PolicyStore } from "../policy-store.js";
4
- import { detectLocalProxy } from "../proxy-guard.js";
5
3
  import { policyPath, readCredential } from "../state.js";
6
- const KEYS = [
7
- "allowedDomains",
8
- "allowCredentials",
9
- "cpu",
10
- "memoryMb",
11
- "tier",
12
- "isolation",
13
- "localhost",
14
- "remoteGrants",
15
- ];
16
- /** Shown before `set tier open` takes effect (adapted from the network ask-to-allow spec §7). */
17
- export const OPEN_TIER_RISK = "At tier open, agent commands on this device can reach any address the organization allows " +
18
- "(any public address if the organization has no limit), including uploading files to " +
19
- "outside sites. Prompt injection can make an agent do that. Turn it on only on your own " +
20
- "development machine, with agents and material you trust.";
21
- /** Printed when a local tier change turned the sandbox back on. */
22
- export const TIER_CHANGE_SANDBOX_ON = "The tier changed, so the sandbox is back on. To run commands without a sandbox again, set " +
23
- "tier open and run: capybara-device policy set isolation none";
24
- /** Shown before `set isolation none` takes effect (spec §5.4). */
25
- export const UNSANDBOXED_RISK_TEXT = "Without a sandbox, agent commands run on this computer as you: they can read and write all " +
26
- "your files, use your credentials (SSH keys, cloud accounts, keychain), Docker and any " +
27
- "network. Prompt injection can make an agent delete files or send your credentials away. " +
28
- "Turn it on only on your own development machine, with agents and material you fully trust. " +
29
- "Such commands can also read this program's own credential: if you suspect misuse, run " +
30
- "capybara-device logout and log in again.";
31
- const OPEN_TIER = {
32
- risk: OPEN_TIER_RISK,
33
- prompt: "Let commands on this device reach any address the organization allows? [y/N] ",
34
- needsYes: "Nothing changed. To set tier open, run: capybara-device policy set tier open --yes",
35
- };
36
- const UNSANDBOXED = {
37
- risk: UNSANDBOXED_RISK_TEXT,
38
- prompt: "Run agent commands on this computer without a sandbox? [y/N] ",
39
- needsYes: "Nothing changed. To run commands without a sandbox, run: " +
40
- "capybara-device policy set isolation none --yes",
41
- };
42
- /** The risk of a `policy` command line, when it is one of the changes that ask first. */
43
- export function policyRisk(cmd) {
44
- if (cmd.action !== "set")
45
- return undefined;
46
- const value = cmd.value.trim().toLowerCase();
47
- if (cmd.key === "tier" && value === "open")
48
- return OPEN_TIER;
49
- if (cmd.key === "isolation" && value === "none")
50
- return UNSANDBOXED;
51
- return undefined;
52
- }
53
- /** `set tier open` or `set isolation none` without `--yes`: the changes that ask first. */
54
- export function needsConfirmation(cmd) {
55
- return cmd.action === "set" && policyRisk(cmd) !== undefined && cmd.yes !== true;
56
- }
57
- /**
58
- * Asks on a terminal before a change that needs it: prints its risk text and the prompt; true
59
- * only for an answer of `y` or `yes`.
60
- */
61
- export async function confirmRisk(cmd, deps) {
62
- const r = policyRisk(cmd);
63
- if (r === undefined)
64
- return true;
65
- deps.out(r.risk);
66
- const answer = (await deps.ask(r.prompt)).trim().toLowerCase();
67
- return answer === "y" || answer === "yes";
68
- }
69
- /** What the OS mode does not enforce yet, shown with every `show` and `set`. */
70
- export const NOT_ENFORCED_NOTE = "Note: in OS mode cpu and memoryMb are not enforced yet, and allowCredentials is not used: " +
71
- "commands get no local credentials.";
4
+ /** The fields `show` prints and `set` may replace. */
5
+ const KEYS = ["allowedDomains", "allowCredentials", "cpu", "memoryMb", "mode"];
6
+ /** What OS mode does not enforce yet, shown with `show` and with a limits change. */
7
+ export const NOT_ENFORCED_NOTE = "Note: in OS mode cpu and memoryMb are not enforced yet; allowCredentials is ignored (auto " +
8
+ "mode already has the owner's credentials, sandbox mode gets none).";
9
+ /** Shown when a Docker-mode device's policy is shown or given allowed domains. */
10
+ export const DOCKER_DOMAIN_NOTE = "Note: this device runs commands in Docker mode, where the mode alone decides network " +
11
+ "access (auto: the default bridge; sandbox: no network). Allowed domains apply in OS mode's " +
12
+ "sandbox only.";
72
13
  function list(value) {
73
14
  return value
74
15
  .split(",")
@@ -84,40 +25,6 @@ function ceiling(key, value) {
84
25
  }
85
26
  return n;
86
27
  }
87
- /** Shown when a docker-mode device is given an allowed domain. */
88
- export const DOCKER_NETWORK_NOTE = "Note: this device runs commands in Docker mode, which cannot limit network access per " +
89
- "domain: while any domain is allowed or the tier is open (and the organization allows " +
90
- "network), commands reach the whole internet. Use OS mode to allow single domains.";
91
- /** Shown when a Docker-mode device is told to run commands without a sandbox. */
92
- export const DOCKER_ISOLATION_REFUSED = "This device runs commands in Docker mode, where they always run in a container; " +
93
- "isolation none works in OS mode only.";
94
- /** Refusal of `set isolation none` while the local tier is not explicitly `open`. */
95
- export const ISOLATION_NEEDS_OPEN = "Nothing changed. Running without a sandbox needs tier open set on this device first: " +
96
- "capybara-device policy set tier open --yes";
97
- /** A refusal found under the policy lock, reported as a usage refusal (exit 2). */
98
- class LockedRefusal extends Error {
99
- }
100
- /**
101
- * Why `set isolation none` cannot apply on this machine now (Docker mode, or the local tier is
102
- * not explicitly `open`), checked before any risk text or question; undefined for every other
103
- * command line. The tier is checked again under the policy lock when the change is written.
104
- */
105
- export function isolationRefusal(cmd, stateDir) {
106
- if (cmd.action !== "set" || cmd.key !== "isolation")
107
- return undefined;
108
- if (cmd.value.trim().toLowerCase() !== "none")
109
- return undefined;
110
- if (dockerMode(stateDir))
111
- return DOCKER_ISOLATION_REFUSED;
112
- try {
113
- if (new PolicyStore(stateDir).current().tier !== "open")
114
- return ISOLATION_NEEDS_OPEN;
115
- }
116
- catch {
117
- // An unreadable policy file is reported by the command itself.
118
- }
119
- return undefined;
120
- }
121
28
  /** Whether this machine is logged in in Docker mode (false when unknown). */
122
29
  function dockerMode(stateDir) {
123
30
  try {
@@ -160,53 +67,40 @@ function edit(current, action, key, values, out) {
160
67
  out(has(current, v) ? `Removed ${v} from ${key}.` : `${v} is not in ${key}.`);
161
68
  return current.filter((x) => !has(values, x));
162
69
  }
163
- function tierValue(value) {
164
- const v = value.trim().toLowerCase();
165
- if (v === "default")
166
- return undefined;
167
- if (!isSandboxTier(v))
168
- throw new Error(`tier must be strict, dev, open or default, got "${value}"`);
169
- return v;
170
- }
171
- /** What `policy show` says the tier gives on this machine (English, one line each). */
172
- export function describeTier(policy, facts, proxy) {
173
- const chosen = policy.tier !== undefined
174
- ? `${policy.tier} (set on this device; the organization's ceiling may lower it)`
175
- : "the organization's default (dev unless the organization changed it)";
176
- const lines = [`Tier: ${chosen}.`];
177
- const localhost = facts.localhost === "on"
178
- ? "commands can listen on local ports and reach this machine's localhost"
179
- : facts.localhost === "off-proxy-detected"
180
- ? `off: a local proxy was detected (${proxy.reasons.join("; ")}). Commands could ` +
181
- "reach past the network allowlist through it. To allow localhost anyway, run: " +
182
- "capybara-device policy set localhost allow"
183
- : "off";
184
- lines.push(`At tier ${facts.effectiveTier} on this machine: localhost ${localhost}.`);
185
- const sockets = facts.unixSockets === "roots"
186
- ? "allowed under the device's workspace, tmp and socket directories only"
187
- : facts.unixSockets === "all-masked"
188
- ? "the container's own"
189
- : "blocked";
190
- lines.push(`Unix sockets: ${sockets}.`);
191
- if (facts.effectiveTier !== "strict") {
192
- lines.push("Package caches are kept in the device directory's cache folder.");
193
- }
194
- if (policy.isolation === "none") {
195
- lines.push("Isolation: none. While the tier is open, commands run directly on this computer as you, " +
196
- "without a sandbox. To turn the sandbox back on, run: " +
197
- "capybara-device policy set isolation sandbox");
198
- }
199
- return lines;
70
+ /** What `policy show` says the mode gives on this machine (English, one line each). */
71
+ export function describeMode(policy, runMode = "os") {
72
+ if (policy.mode === "auto") {
73
+ if (runMode === "docker") {
74
+ return [
75
+ "Mode: auto. Commands run in the device's container on its default bridge, and the " +
76
+ "platform's file tools reach any path in the container; the deployment reviews every " +
77
+ "command and blocks or asks about dangerous ones.",
78
+ ];
79
+ }
80
+ return [
81
+ "Mode: auto. Commands run as you on this machine, with their files, credentials and " +
82
+ "network; the deployment reviews every command and blocks or asks about dangerous ones.",
83
+ "Allowed domains apply in sandbox mode only (capybara-device mode sandbox).",
84
+ ];
85
+ }
86
+ if (runMode === "docker") {
87
+ return [
88
+ "Mode: sandbox. Commands run in the device's container with no network; only the " +
89
+ "workspace, skills and temporary files are writable.",
90
+ ];
91
+ }
92
+ return [
93
+ "Mode: sandbox. Only the workspace, skills and temporary files are writable; the network " +
94
+ "reaches the allowed hosts.",
95
+ ];
200
96
  }
201
97
  /**
202
- * `policy show` prints the local policy and what its tier gives on this machine;
203
- * `policy set <key> <value>` replaces one field (`set tier open` and `set isolation none` print
204
- * their risk and need `--yes` or a confirmation at the prompt); `policy add|remove <key> <value>`
205
- * adds or removes entries of a list field. `tier default` removes the key (follow the org's
206
- * default). The machine's user edits this file; the deployment changes it only through the
207
- * `policy` op, on the device owner's decision and only while `remoteGrants` is `owner`
208
- * (narrowing always; never `isolation none`). Writes take policy.json.lock, and a running program
209
- * applies the change at its next command.
98
+ * `policy show` prints the local policy and what its mode gives on this machine;
99
+ * `policy set <key> <value>` replaces one field; `policy add|remove <key> <value>` adds or removes
100
+ * entries of a list field. The mode is set with `capybara-device mode`. The machine's user edits
101
+ * this file; the deployment changes it only through the `policy` op (narrowing only: hosts and
102
+ * `mode: "sandbox"`, never auto). Writes take policy.json.lock, and a running program applies the
103
+ * change at its next command.
210
104
  */
211
105
  export async function policyCommand(cmd, deps) {
212
106
  const { stateDir, out, err } = deps;
@@ -218,17 +112,14 @@ export async function policyCommand(cmd, deps) {
218
112
  err(`Cannot read ${policyPath(stateDir)}: ${e.message}`);
219
113
  return 1;
220
114
  }
115
+ const docker = dockerMode(stateDir);
221
116
  if (cmd.action === "show") {
222
117
  const policy = store.current();
223
118
  out(JSON.stringify(policy, null, 2));
224
- const proxy = await (deps.detectProxy ?? (() => detectLocalProxy()))();
225
- const facts = tierFacts(policy, undefined, {
226
- ...(deps.platform !== undefined && { platform: deps.platform }),
227
- proxyDetected: proxy.detected,
228
- mode: dockerMode(stateDir) ? "docker" : "os",
229
- });
230
- for (const l of describeTier(policy, facts, proxy))
119
+ for (const l of describeMode(policy, docker ? "docker" : "os"))
231
120
  out(l);
121
+ if (docker)
122
+ out(DOCKER_DOMAIN_NOTE);
232
123
  out(NOT_ENFORCED_NOTE);
233
124
  return 0;
234
125
  }
@@ -254,70 +145,18 @@ export async function policyCommand(cmd, deps) {
254
145
  change = (p) => ({ ...p, [key]: next });
255
146
  break;
256
147
  }
257
- case "tier": {
258
- const next = tierValue(value);
259
- change = (p, say) => {
260
- const { tier: old, ...rest } = p;
261
- // Any tier change turns the sandbox back on (spec §5.4: running without one starts
262
- // only with a confirmed set isolation none, never by a later tier change).
263
- const isolation = p.isolation === "none" && next !== old ? "sandbox" : p.isolation;
264
- if (isolation !== p.isolation)
265
- say(TIER_CHANGE_SANDBOX_ON);
266
- return next === undefined ? { ...rest, isolation } : { ...rest, tier: next, isolation };
267
- };
268
- break;
269
- }
270
- case "isolation": {
271
- const v = value.trim().toLowerCase();
272
- if (v !== "sandbox" && v !== "none") {
273
- throw new Error(`isolation must be sandbox or none, got "${value}"`);
274
- }
275
- if (v === "none" && dockerMode(stateDir)) {
276
- err(DOCKER_ISOLATION_REFUSED);
277
- return 2;
278
- }
279
- // Only an explicit local tier open: the org's default can change under the device.
280
- if (v === "none" && store.current().tier !== "open") {
281
- err(ISOLATION_NEEDS_OPEN);
282
- return 2;
283
- }
284
- change = (p) => {
285
- // Judged again on the file as it is under the lock (the tier may have changed).
286
- if (v === "none" && p.tier !== "open")
287
- throw new LockedRefusal(ISOLATION_NEEDS_OPEN);
288
- return { ...p, isolation: v };
289
- };
290
- break;
291
- }
292
- case "localhost": {
293
- const v = value.trim().toLowerCase();
294
- if (v !== "auto" && v !== "allow") {
295
- throw new Error(`localhost must be auto or allow, got "${value}"`);
296
- }
297
- change = (p) => ({ ...p, localhost: v });
298
- break;
299
- }
300
- case "remoteGrants": {
301
- if (value !== "owner" && value !== "off") {
302
- throw new Error(`remoteGrants must be owner or off, got "${value}"`);
303
- }
304
- change = (p) => ({ ...p, remoteGrants: value });
305
- break;
306
- }
148
+ case "mode":
149
+ throw new Error("the mode is set with: capybara-device mode auto|sandbox");
307
150
  case "network":
308
- throw new Error("network is replaced by tier: use capybara-device policy set tier strict|dev|open");
151
+ case "tier":
152
+ case "isolation":
153
+ case "localhost":
154
+ case "remoteGrants":
155
+ throw new Error(`"${key}" is gone: the mode is set with capybara-device mode auto|sandbox; ` +
156
+ `allowedDomains with capybara-device policy add allowedDomains <host>`);
309
157
  default:
310
158
  throw new Error(`unknown policy key "${key}"; one of ${KEYS.join(", ")}`);
311
159
  }
312
- // Widening to tier open or isolation none needs a confirmation; narrowing never does.
313
- const risk = policyRisk(cmd);
314
- if (risk !== undefined && deps.confirmed !== true) {
315
- out(risk.risk);
316
- if (cmd.yes !== true) {
317
- err(risk.needsYes);
318
- return 2;
319
- }
320
- }
321
160
  }
322
161
  else {
323
162
  if (!LIST_KEYS.includes(key)) {
@@ -345,46 +184,20 @@ export async function policyCommand(cmd, deps) {
345
184
  next = store.update((p) => change(p, (l) => lines.push(l)));
346
185
  }
347
186
  catch (e) {
348
- if (e instanceof LockedRefusal) {
349
- err(e.message);
350
- return 2;
351
- }
352
187
  err(`Cannot change ${policyPath(stateDir)}: ${e.message}`);
353
188
  return 1;
354
189
  }
355
190
  for (const l of lines)
356
191
  out(l);
357
192
  out(`Saved ${policyPath(stateDir)}. A running capybara-device applies it at the next command.`);
358
- const docker = dockerMode(stateDir);
359
- if (key === "allowedDomains" && action !== "remove" && docker) {
360
- if (next.allowedDomains.length > 0)
361
- out(DOCKER_NETWORK_NOTE);
362
- }
363
- if (key === "tier") {
364
- out(next.tier === undefined
365
- ? "This device now follows the organization's default tier."
366
- : `This device now asks for tier ${next.tier}; the organization's ceiling may lower it.`);
367
- if (next.tier === "open" && docker)
368
- out(DOCKER_NETWORK_NOTE);
369
- }
370
- if (key === "isolation") {
371
- out(next.isolation === "none"
372
- ? "While the tier is open, commands run on this computer without a sandbox."
373
- : "Commands run in the sandbox.");
374
- }
375
- if (key === "localhost") {
376
- out(next.localhost === "allow"
377
- ? "At tier dev or open, commands can reach this machine's localhost even when a local " +
378
- "proxy runs (it may forward past the network allowlist)."
379
- : "At tier dev or open, commands reach localhost unless a local proxy is detected.");
380
- }
381
- if (key === "remoteGrants") {
382
- out(value === "owner"
383
- ? "The device owner can now widen this device's network from the web or a chat card."
384
- : "The deployment can no longer widen this device's network; it can still narrow it.");
385
- }
386
- if (!["allowedDomains", "tier", "isolation", "localhost", "remoteGrants"].includes(key)) {
193
+ if (key === "allowedDomains") {
194
+ out(docker
195
+ ? DOCKER_DOMAIN_NOTE
196
+ : next.mode === "auto"
197
+ ? "Allowed domains apply in sandbox mode only; switch with: capybara-device mode sandbox"
198
+ : "Sandboxed commands may reach these domains when the organization allows them too.");
199
+ }
200
+ if (key === "cpu" || key === "memoryMb" || key === "allowCredentials")
387
201
  out(NOT_ENFORCED_NOTE);
388
- }
389
202
  return 0;
390
203
  }
@@ -16,7 +16,7 @@ export interface StartDeps {
16
16
  kill?: typeof process.kill;
17
17
  connect?: typeof connect;
18
18
  }
19
- /** Printed at start while policy.json still has the legacy `network: "open"` (spec §12). */
20
- export declare const LEGACY_NETWORK_NOTICE: string;
19
+ /** Printed once when policy.json was written before auto mode (spec §4.4). */
20
+ export declare function legacyPolicyNotice(mode: "auto" | "sandbox"): string;
21
21
  /** `start`: connect and serve in the foreground until stopped, drained, revoked or replaced. */
22
22
  export declare function start(deps: StartDeps): Promise<number>;
@@ -1,13 +1,15 @@
1
1
  import { connect } from "../client.js";
2
2
  import { CommandLog } from "../command-log.js";
3
+ import { sandboxUnavailableMessage } from "../exec/sandbox-messages.js";
3
4
  import { readRunningPid, removePid, writePid } from "../pid.js";
4
5
  import { PolicyStore } from "../policy-store.js";
5
6
  import { rotateServiceLog } from "../service/launchd.js";
6
7
  import { readCredential } from "../state.js";
7
- /** Printed at start while policy.json still has the legacy `network: "open"` (spec §12). */
8
- export const LEGACY_NETWORK_NOTICE = "policy.json: `network` is replaced by `tier`; run `capybara-device policy set tier open` " +
9
- "to keep an unlimited network. Any `capybara-device policy set` removes the old key and this " +
10
- "notice.";
8
+ /** Printed once when policy.json was written before auto mode (spec §4.4). */
9
+ export function legacyPolicyNotice(mode) {
10
+ return ("policy.json now uses `mode`; this machine runs in " +
11
+ `${mode} mode; switch with \`capybara-device mode\`.`);
12
+ }
11
13
  /** `start`: connect and serve in the foreground until stopped, drained, revoked or replaced. */
12
14
  export async function start(deps) {
13
15
  const { stateDir, out, err } = deps;
@@ -58,9 +60,15 @@ export async function start(deps) {
58
60
  try {
59
61
  // An invalid policy.json stops the start; later, a broken edit keeps the last good policy.
60
62
  policy = new PolicyStore(stateDir, { err });
61
- if (policy.legacyNetworkOpen)
62
- out(LEGACY_NETWORK_NOTICE);
63
+ if (policy.legacy)
64
+ out(legacyPolicyNotice(policy.current().mode));
63
65
  executor = await deps.createExecutor(cred, policy);
66
+ // Without the OS sandbox the device keeps serving: auto mode works, and sandbox mode
67
+ // refuses every command with this reason. A policy set to sandbox says so at start.
68
+ const sandbox = executor;
69
+ if (sandbox.available === false && policy.current().mode === "sandbox") {
70
+ err(sandboxUnavailableMessage(sandbox.unavailableReason ?? ""));
71
+ }
64
72
  }
65
73
  catch (e) {
66
74
  err(`Cannot start: ${e.message}`);
@@ -1,4 +1,4 @@
1
- import { readCredential } from "../state.js";
1
+ import { readCredential, readPolicy } from "../state.js";
2
2
  /** `status`: exit 0 when logged in, 1 when not (or the credential file is unusable). */
3
3
  export function status(stateDir, json, out, err) {
4
4
  let cred;
@@ -13,10 +13,18 @@ export function status(stateDir, json, out, err) {
13
13
  out(json ? JSON.stringify({ loggedIn: false }) : "Not logged in.");
14
14
  return 1;
15
15
  }
16
+ // An unreadable policy file is reported by `start` and `policy show`; status still answers.
17
+ let sandboxMode;
18
+ try {
19
+ sandboxMode = readPolicy(stateDir).mode;
20
+ }
21
+ catch {
22
+ sandboxMode = undefined;
23
+ }
16
24
  // The credential itself is never printed.
17
25
  const { credential: _secret, ...shown } = cred;
18
26
  if (json) {
19
- out(JSON.stringify({ loggedIn: true, ...shown }));
27
+ out(JSON.stringify({ loggedIn: true, ...shown, ...(sandboxMode && { sandboxMode }) }));
20
28
  }
21
29
  else {
22
30
  out([
@@ -25,7 +33,7 @@ export function status(stateDir, json, out, err) {
25
33
  ` organization: ${cred.orgId}`,
26
34
  ` device: ${cred.deviceId}`,
27
35
  ` directory: ${cred.dir}`,
28
- ` mode: ${cred.mode}`,
36
+ ` mode: ${cred.mode} | ${sandboxMode ?? "unknown"}`,
29
37
  ].join("\n"));
30
38
  }
31
39
  return 0;
@@ -1,5 +1,4 @@
1
- import { type DeviceExecArgs, type ExecResult, type SandboxRoots, type SandboxTier } from "@capybara-hq/plugin-sdk";
2
- import { type EgressLimits, type TierFacts } from "../policy.js";
1
+ import { type DeviceExecArgs, type ExecResult, type SandboxRoots } from "@capybara-hq/plugin-sdk";
3
2
  import type { Policy } from "../state.js";
4
3
  import { type Executor } from "./types.js";
5
4
  /** The version of the published sandbox images this program runs commands in. */
@@ -11,20 +10,6 @@ export declare const SANDBOX_IMAGE = "ghcr.io/capybara-hq/capybara-sandbox:0.1.0
11
10
  * Docker Desktop (macOS) maps file ownership itself, so the image's user is used there.
12
11
  */
13
12
  export declare function containerUser(platform?: NodeJS.Platform, uid?: number | undefined, gid?: number | undefined): string;
14
- /**
15
- * The container's `--shm-size` for a tier (spec §5.2): `strict` keeps Docker's default (64 MiB);
16
- * `dev` and `open` get a quarter of the memory ceiling up to 1 GiB (at least the default), or
17
- * 1 GiB without a ceiling, so browsers have room.
18
- */
19
- export declare function shmSize(tier: SandboxTier, memoryMb: number | null): string | undefined;
20
- /**
21
- * Whether a command gets the default bridge (spec §5.2 table). Docker mode has no domain filter,
22
- * and the bridge reaches the host and the intranet, so only an explicit choice opens it: the
23
- * device's own allowed domains within the ceiling (as `strict` computes them; the dev hosts do
24
- * not count), or tier `open` with a ceiling that allows any host (an allowlist ceiling at `open`
25
- * counts only its explicit local domains, like the lower tiers).
26
- */
27
- export declare function bridgeNetwork(policy: Policy, limits: EgressLimits): boolean;
28
13
  /** Container name of a device. */
29
14
  export declare function containerName(deviceId: string): string;
30
15
  /** Whether the docker CLI can reach a daemon, and why not. */
@@ -39,9 +24,8 @@ export interface DockerExecutorOptions {
39
24
  dir: string;
40
25
  deviceId: string;
41
26
  /**
42
- * The local policy now. The network decision reads it at each command; cpu, memory and the
43
- * tier's shm size apply when the container is next created (at the next command that finds it
44
- * idle).
27
+ * The local policy now. The network decision reads it at each command; cpu and memory apply
28
+ * when the container is next created (at the next command that finds it idle).
45
29
  */
46
30
  policy: () => Policy;
47
31
  }
@@ -51,10 +35,10 @@ export interface DockerExecutorOptions {
51
35
  * /workspace, /skills and /tmp. Workspace and tmp files are read and written inside the container
52
36
  * (as the `sandbox` user, so a link a command plants resolves in the container and never on the
53
37
  * host); the skills directory, which commands cannot write, is accessed from the host with the
54
- * same real-path checks as the OS executor. Network: none unless {@link bridgeNetwork} says
55
- * otherwise, then the default bridge (Docker mode has no domain allowlist). Tiers `dev` and
56
- * `open` get a larger `/dev/shm` ({@link shmSize}); a change of the container's flags recreates it
57
- * at the next command that finds it idle.
38
+ * same real-path checks as the OS executor. Auto mode: the container on its default bridge, and
39
+ * file operations reach any absolute path in the container. Sandbox mode: no network attached and
40
+ * file operations stay in the mounted roots. Docker mode has no per-domain filter. A change of the
41
+ * container's flags recreates it at the next command that finds it idle.
58
42
  */
59
43
  export declare class DockerExecutor implements Executor {
60
44
  private readonly opts;
@@ -76,8 +60,10 @@ export declare class DockerExecutor implements Executor {
76
60
  private readonly queue;
77
61
  private pumping;
78
62
  private dirty;
79
- /** The limits of the latest command: they decide the tier the container is made for. */
63
+ /** The limits of the latest command: the kernel's mode ceiling for file operations. */
80
64
  private lastLimits;
65
+ /** When {@link lastLimits} came (file operations follow it only inside the window). */
66
+ private lastLimitsAt;
81
67
  /** The spec hash of the container in use (set when it is created or reused). */
82
68
  private spec;
83
69
  constructor(opts: DockerExecutorOptions);
@@ -86,10 +72,13 @@ export declare class DockerExecutor implements Executor {
86
72
  private serial;
87
73
  private inspect;
88
74
  private wanted;
89
- /** The tier commands run at now (the owner's choice, else `dev`, before any command). */
90
- tier(policy?: Policy): SandboxTier;
91
- /** What the tier gives in this mode (for the policy summary). */
92
- tierFacts(policy?: Policy): TierFacts;
75
+ /**
76
+ * The mode file operations use now. File operations carry no limits and never pass command
77
+ * review, so they use the sandboxed result before any exec and once the latest decision is stale
78
+ * (the safe default for an organization whose ceiling is sandbox), else
79
+ * `effectiveMode(policy, limits)`.
80
+ */
81
+ private modeNow;
93
82
  /** Every `docker run` flag of the container except its name and spec label. */
94
83
  private runArgs;
95
84
  /** A hash of the run flags: a container made with other flags is recreated. */
@@ -100,7 +89,7 @@ export declare class DockerExecutor implements Executor {
100
89
  /**
101
90
  * Creates the container, or reuses the existing one when it matches; call inside `serial`.
102
91
  * A file operation (`anySpec`) reuses any container that sees the directory: it needs no
103
- * particular flags, and before the first command the tier is not known yet. The next command
92
+ * particular flags, and before the first command the policy is not known yet. The next command
104
93
  * that finds it idle recreates it if its flags differ.
105
94
  */
106
95
  private ensureContainer;
@@ -125,7 +114,10 @@ export declare class DockerExecutor implements Executor {
125
114
  private noteFailure;
126
115
  exec(args: DeviceExecArgs, signal: AbortSignal): Promise<ExecResult>;
127
116
  private run;
128
- /** `path` made absolute and normalized; refused unless lexically under a root. */
117
+ /**
118
+ * `path` made absolute and normalized. Auto mode accepts any clean absolute path (the container
119
+ * is the boundary); sandbox mode refuses anything outside the mounted roots.
120
+ */
129
121
  private containerPath;
130
122
  /** The host path of a /skills path (the skills directory is mounted read only). */
131
123
  private skillsHostPath;