operon-os-sandbox 0.1.0-alpha.2 → 0.1.0-alpha.20

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
@@ -1,12 +1,12 @@
1
1
  # operon-os-sandbox
2
2
 
3
- OS-level command sandboxing for the local Machine. Every `Machine.run` — the
3
+ OS-level command sandboxing for the local Environment. Every `Environment.run` — the
4
4
  bash tool, search binaries, user hooks, everything — is wrapped in the
5
5
  platform sandbox before it spawns: **Seatbelt** (`sandbox-exec`) on macOS,
6
6
  **bubblewrap** on Linux, via
7
7
  [`@anthropic-ai/sandbox-runtime`](https://github.com/anthropic-experimental/sandbox-runtime) (srt).
8
8
 
9
- - **Filesystem**: writes are allowed only under each machine's cwd +
9
+ - **Filesystem**: writes are allowed only under each environment's cwd +
10
10
  `additionalDirs` + tmp + the framework's task-log dir; reads are open except
11
11
  srt's built-in credential protections plus your `denyRead`.
12
12
  - **Network**: deny-all by default. Traffic is forced through a local
@@ -17,7 +17,7 @@ platform sandbox before it spawns: **Seatbelt** (`sandbox-exec`) on macOS,
17
17
  *why* a command failed instead of a bare exit code. Known-benign startup
18
18
  noise is filtered.
19
19
  - **Degrade, don't break**: unsupported platform (Windows) or missing
20
- dependencies (no `bwrap`) → `machine()` returns a plain `LocalMachine` and
20
+ dependencies (no `bwrap`) → `environment()` returns a plain `LocalEnvironment` and
21
21
  `status.reason` says why. Same API either way.
22
22
 
23
23
  ## Usage
@@ -38,10 +38,10 @@ const sandbox = await OsSandbox.start({
38
38
  });
39
39
  if (!sandbox.status.enabled) console.warn(`os-sandbox off: ${sandbox.status.reason}`);
40
40
 
41
- // Wherever you previously built the machine:
42
- // machine: new LocalMachine(WORK)
41
+ // Wherever you previously built the environment:
42
+ // environment: new LocalEnvironment(WORK)
43
43
  // becomes:
44
- const machine = sandbox.machine(WORK);
44
+ const environment = sandbox.environment(WORK);
45
45
 
46
46
  // ... hand it to createAgent / the session as usual. withCwd() siblings
47
47
  // (subagent worktrees) stay sandboxed automatically.
@@ -49,7 +49,7 @@ const machine = sandbox.machine(WORK);
49
49
  await sandbox.dispose(); // on shutdown
50
50
  ```
51
51
 
52
- Only local machines are wrapped — SSH and vendor-sandbox machines run their
52
+ Only local environments are wrapped — SSH and vendor-sandbox environments run their
53
53
  commands elsewhere, so this layer deliberately does not touch them. Direct
54
54
  file I/O (`readBytes`/`writeText`/…) is also untouched: those are the
55
55
  framework's own code paths, gated by its path-access policy; the OS sandbox
@@ -61,14 +61,14 @@ exists for arbitrary *commands*, which have no such gate.
61
61
  - **Linux**: `bubblewrap`, `socat`, `ripgrep` installed. Ubuntu 24.04+ needs
62
62
  `kernel.apparmor_restrict_unprivileged_userns=0` (or an AppArmor userns
63
63
  profile). Missing pieces are reported in `status.reason` and the sandbox
64
- degrades to plain `LocalMachine`.
64
+ degrades to plain `LocalEnvironment`.
65
65
  - **Windows**: not supported by this package (srt's Windows backend is alpha
66
66
  and needs an elevated install); always degrades.
67
67
 
68
68
  ## Caveats
69
69
 
70
70
  - One `OsSandbox` per process — srt's `SandboxManager` is a process-wide
71
- singleton. Different machines (different cwds) are fine; a second `start()`
71
+ singleton. Different environments (different cwds) are fine; a second `start()`
72
72
  with a different config is not.
73
73
  - The network allowlist only serves proxy-aware clients (HTTP/HTTPS via env
74
74
  vars, TCP via SOCKS). Raw-TCP clients that ignore proxies — plain `ssh`, DB
@@ -1,7 +1,7 @@
1
- import { LocalMachine, type Machine, type RunCommandOptions, type RunCommandResult } from "operon-agents-core";
1
+ import { LocalEnvironment, type Environment, type RunCommandOptions, type RunCommandResult } from "operon-agents-core";
2
2
  /**
3
- * The resolved write/read policy every sandboxed machine of one OsSandbox
4
- * shares. Immutable — a machine contributes only its own cwd/additionalDirs
3
+ * The resolved write/read policy every sandboxed environment of one OsSandbox
4
+ * shares. Immutable — an environment contributes only its own cwd/additionalDirs
5
5
  * on top, per call.
6
6
  */
7
7
  export interface SandboxPolicyContext {
@@ -11,7 +11,7 @@ export interface SandboxPolicyContext {
11
11
  readonly allowWrite: readonly string[];
12
12
  }
13
13
  /**
14
- * A LocalMachine whose `run` goes through the OS sandbox: the argv is wrapped
14
+ * A LocalEnvironment whose `run` goes through the OS sandbox: the argv is wrapped
15
15
  * by @anthropic-ai/sandbox-runtime (Seatbelt on macOS, bubblewrap on Linux)
16
16
  * before it is spawned, and sandbox denials observed during the run are
17
17
  * annotated onto the result's stderr so callers see WHY a command failed.
@@ -20,22 +20,22 @@ export interface SandboxPolicyContext {
20
20
  * framework's own code path, gated by its path-access policy — the sandbox
21
21
  * exists for arbitrary COMMANDS, which have no such gate.
22
22
  */
23
- export declare class SandboxedLocalMachine extends LocalMachine {
23
+ export declare class SandboxedLocalEnvironment extends LocalEnvironment {
24
24
  private readonly policy;
25
25
  constructor(policy: SandboxPolicyContext, cwdOrOptions?: string | {
26
26
  cwd?: string;
27
27
  additionalDirs?: readonly string[];
28
28
  });
29
29
  /** Re-rooted siblings (subagent worktrees) stay sandboxed — same policy, new cwd. */
30
- withCwd(cwd: string): Machine;
30
+ withCwd(cwd: string): Environment;
31
31
  run(argv: readonly string[], options?: RunCommandOptions): Promise<RunCommandResult>;
32
32
  /**
33
- * Every machine states the full filesystem policy per call: srt falls back
33
+ * Every environment states the full filesystem policy per call: srt falls back
34
34
  * per-FIELD (`?? config`), and an empty array is not undefined — restating
35
- * the session lists plus this machine's own roots is the only spelling that
35
+ * the session lists plus this environment's own roots is the only spelling that
36
36
  * cannot accidentally drop either half.
37
37
  */
38
38
  private perCallConfig;
39
39
  private annotateViolations;
40
40
  }
41
- //# sourceMappingURL=machine.d.ts.map
41
+ //# sourceMappingURL=environment.d.ts.map
@@ -1,5 +1,5 @@
1
1
  import { isAbsolute, resolve } from "node:path";
2
- import { LocalMachine } from "operon-agents-core";
2
+ import { LocalEnvironment } from "operon-agents-core";
3
3
  import { SandboxManager } from "@anthropic-ai/sandbox-runtime";
4
4
  import { toSrtInvocation } from "./srt-command.js";
5
5
  /** The macOS violation monitor tails `log stream`, which reports denials with a
@@ -7,7 +7,7 @@ import { toSrtInvocation } from "./srt-command.js";
7
7
  const VIOLATION_SETTLE_MS = 250;
8
8
  let commandCounter = 0;
9
9
  /**
10
- * A LocalMachine whose `run` goes through the OS sandbox: the argv is wrapped
10
+ * A LocalEnvironment whose `run` goes through the OS sandbox: the argv is wrapped
11
11
  * by @anthropic-ai/sandbox-runtime (Seatbelt on macOS, bubblewrap on Linux)
12
12
  * before it is spawned, and sandbox denials observed during the run are
13
13
  * annotated onto the result's stderr so callers see WHY a command failed.
@@ -16,7 +16,7 @@ let commandCounter = 0;
16
16
  * framework's own code path, gated by its path-access policy — the sandbox
17
17
  * exists for arbitrary COMMANDS, which have no such gate.
18
18
  */
19
- export class SandboxedLocalMachine extends LocalMachine {
19
+ export class SandboxedLocalEnvironment extends LocalEnvironment {
20
20
  policy;
21
21
  constructor(policy, cwdOrOptions = process.cwd()) {
22
22
  super(cwdOrOptions);
@@ -25,20 +25,20 @@ export class SandboxedLocalMachine extends LocalMachine {
25
25
  /** Re-rooted siblings (subagent worktrees) stay sandboxed — same policy, new cwd. */
26
26
  withCwd(cwd) {
27
27
  const absolute = isAbsolute(cwd) ? cwd : resolve(this.getcwd(), cwd);
28
- return new SandboxedLocalMachine(this.policy, { cwd: absolute, additionalDirs: this.additionalDirs() });
28
+ return new SandboxedLocalEnvironment(this.policy, { cwd: absolute, additionalDirs: this.additionalDirs() });
29
29
  }
30
30
  async run(argv, options = {}) {
31
31
  // The sandbox session died or was never initialized — refuse rather than
32
32
  // silently running unsandboxed. Hosts that want no sandbox build a plain
33
- // LocalMachine (OsSandbox.machine already does this when disabled).
33
+ // LocalEnvironment (OsSandbox.environment already does this when disabled).
34
34
  if (!SandboxManager.isSandboxingEnabled()) {
35
- throw new Error("os-sandbox: SandboxManager is not initialized; use OsSandbox.start() and build machines through it.");
35
+ throw new Error("os-sandbox: SandboxManager is not initialized; use OsSandbox.start() and build environments through it.");
36
36
  }
37
- // Fold a per-run cwd override into the argv exactly as BaseMachine.run
37
+ // Fold a per-run cwd override into the argv exactly as BaseEnvironment.run
38
38
  // would — the sandbox must wrap the FINAL command, subshell and all.
39
39
  const { cwd, ...rest } = options;
40
40
  const effective = cwd === undefined ? argv : this.withCwdArgv(argv, cwd);
41
- const { command, binShell } = toSrtInvocation(effective, this.osEnv.shellPath);
41
+ const { command, binShell } = toSrtInvocation(effective, this.osInfo.shellPath);
42
42
  // A unique id, not the command text: srt compares attribution keys on
43
43
  // their first 100 chars, so long commands sharing a prefix would
44
44
  // cross-attribute violations.
@@ -48,7 +48,7 @@ export class SandboxedLocalMachine extends LocalMachine {
48
48
  const wrapped = await SandboxManager.wrapWithSandboxArgv(command, binShell, this.perCallConfig(), options.signal, this.getcwd(), { commandId, commandText: command });
49
49
  wrappedArgv = wrapped.argv;
50
50
  // wrapped.env is process.env verbatim on macOS/Linux (proxy vars are baked
51
- // into the wrapped script) and LocalMachine already layers the caller's
51
+ // into the wrapped script) and LocalEnvironment already layers the caller's
52
52
  // overrides over the ambient env — so it is deliberately not forwarded.
53
53
  }
54
54
  catch (error) {
@@ -60,9 +60,9 @@ export class SandboxedLocalMachine extends LocalMachine {
60
60
  return stderr === result.stderr ? result : { ...result, stderr };
61
61
  }
62
62
  /**
63
- * Every machine states the full filesystem policy per call: srt falls back
63
+ * Every environment states the full filesystem policy per call: srt falls back
64
64
  * per-FIELD (`?? config`), and an empty array is not undefined — restating
65
- * the session lists plus this machine's own roots is the only spelling that
65
+ * the session lists plus this environment's own roots is the only spelling that
66
66
  * cannot accidentally drop either half.
67
67
  */
68
68
  perCallConfig() {
@@ -87,4 +87,4 @@ export class SandboxedLocalMachine extends LocalMachine {
87
87
  return stderr;
88
88
  }
89
89
  }
90
- //# sourceMappingURL=machine.js.map
90
+ //# sourceMappingURL=environment.js.map
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { OsSandbox } from "./os-sandbox.ts";
2
- export { SandboxedLocalMachine, type SandboxPolicyContext } from "./machine.ts";
2
+ export { SandboxedLocalEnvironment, type SandboxPolicyContext } from "./environment.ts";
3
3
  export { toSrtInvocation, shellQuoteArg, type SrtInvocation } from "./srt-command.ts";
4
4
  export type { OsSandboxOptions, OsSandboxNetworkOptions, OsSandboxFilesystemOptions, OsSandboxStatus, NetworkAskRequest, } from "./types.ts";
5
5
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  export { OsSandbox } from "./os-sandbox.js";
2
- export { SandboxedLocalMachine } from "./machine.js";
2
+ export { SandboxedLocalEnvironment } from "./environment.js";
3
3
  export { toSrtInvocation, shellQuoteArg } from "./srt-command.js";
4
4
  //# sourceMappingURL=index.js.map
@@ -1,17 +1,17 @@
1
- import { type Machine } from "operon-agents-core";
1
+ import { type Environment } from "operon-agents-core";
2
2
  import type { OsSandboxOptions, OsSandboxStatus } from "./types.ts";
3
3
  /**
4
- * Process-wide OS sandbox session for LOCAL machines.
4
+ * Process-wide OS sandbox session for LOCAL environments.
5
5
  *
6
6
  * `start()` never throws: on macOS/Linux with dependencies present it
7
7
  * initializes @anthropic-ai/sandbox-runtime (which starts the network filter
8
- * proxy) and `machine()` mints {@link SandboxedLocalMachine}s; anywhere else
9
- * `status.enabled` is false and `machine()` mints plain {@link LocalMachine}s
8
+ * proxy) and `environment()` mints {@link SandboxedLocalEnvironment}s; anywhere else
9
+ * `status.enabled` is false and `environment()` mints plain {@link LocalEnvironment}s
10
10
  * — same API, today's behavior, and `status.reason` says why.
11
11
  *
12
12
  * One OsSandbox per process: the underlying SandboxManager is a module-level
13
13
  * singleton, so a second concurrent `start()` with a different config would
14
- * silently share the first one's session. Remote machines (SSH, vendor
14
+ * silently share the first one's session. Remote environments (SSH, vendor
15
15
  * sandboxes) are out of scope by design — their commands do not run on this
16
16
  * host.
17
17
  */
@@ -20,17 +20,17 @@ export declare class OsSandbox {
20
20
  private readonly policy;
21
21
  private constructor();
22
22
  static start(options?: OsSandboxOptions): Promise<OsSandbox>;
23
- /** An explicitly-off OsSandbox: same `machine()` API, plain LocalMachines. */
23
+ /** An explicitly-off OsSandbox: same `environment()` API, plain LocalEnvironments. */
24
24
  static disabled(reason?: string): OsSandbox;
25
25
  /**
26
- * Build the machine a session should get — sandboxed when this OsSandbox is
27
- * enabled, a plain LocalMachine otherwise. Accepts exactly what LocalMachine's
26
+ * Build the environment a session should get — sandboxed when this OsSandbox is
27
+ * enabled, a plain LocalEnvironment otherwise. Accepts exactly what LocalEnvironment's
28
28
  * constructor does.
29
29
  */
30
- machine(cwdOrOptions?: string | {
30
+ environment(cwdOrOptions?: string | {
31
31
  cwd?: string;
32
32
  additionalDirs?: readonly string[];
33
- }): Machine;
33
+ }): Environment;
34
34
  /** Tear down the srt session (filter proxies, monitors). Idempotent. */
35
35
  dispose(): Promise<void>;
36
36
  }
@@ -1,10 +1,10 @@
1
1
  import { realpathSync } from "node:fs";
2
2
  import { homedir, tmpdir } from "node:os";
3
- import { LocalMachine } from "operon-agents-core";
3
+ import { LocalEnvironment } from "operon-agents-core";
4
4
  import { SandboxManager } from "@anthropic-ai/sandbox-runtime";
5
- import { SandboxedLocalMachine } from "./machine.js";
5
+ import { SandboxedLocalEnvironment } from "./environment.js";
6
6
  /**
7
- * Write roots every sandboxed machine needs regardless of its cwd:
7
+ * Write roots every sandboxed environment needs regardless of its cwd:
8
8
  * the temp trees (both the symlink and its real path — srt matches paths
9
9
  * literally), and the framework's background-task log directory — the bash
10
10
  * tool redirects background/attached command output to
@@ -57,24 +57,24 @@ function buildRuntimeConfig(options) {
57
57
  },
58
58
  filesystem: {
59
59
  denyRead: [...(options.filesystem?.denyRead ?? [])],
60
- // Session-level extras only; each machine adds its own cwd tree per call.
60
+ // Session-level extras only; each environment adds its own cwd tree per call.
61
61
  allowWrite: [...(options.filesystem?.allowWrite ?? [])],
62
62
  denyWrite: [...(options.filesystem?.denyWrite ?? [])],
63
63
  },
64
64
  };
65
65
  }
66
66
  /**
67
- * Process-wide OS sandbox session for LOCAL machines.
67
+ * Process-wide OS sandbox session for LOCAL environments.
68
68
  *
69
69
  * `start()` never throws: on macOS/Linux with dependencies present it
70
70
  * initializes @anthropic-ai/sandbox-runtime (which starts the network filter
71
- * proxy) and `machine()` mints {@link SandboxedLocalMachine}s; anywhere else
72
- * `status.enabled` is false and `machine()` mints plain {@link LocalMachine}s
71
+ * proxy) and `environment()` mints {@link SandboxedLocalEnvironment}s; anywhere else
72
+ * `status.enabled` is false and `environment()` mints plain {@link LocalEnvironment}s
73
73
  * — same API, today's behavior, and `status.reason` says why.
74
74
  *
75
75
  * One OsSandbox per process: the underlying SandboxManager is a module-level
76
76
  * singleton, so a second concurrent `start()` with a different config would
77
- * silently share the first one's session. Remote machines (SSH, vendor
77
+ * silently share the first one's session. Remote environments (SSH, vendor
78
78
  * sandboxes) are out of scope by design — their commands do not run on this
79
79
  * host.
80
80
  */
@@ -110,19 +110,19 @@ export class OsSandbox {
110
110
  };
111
111
  return new OsSandbox({ enabled: true, platform, warnings: deps.warnings }, policy);
112
112
  }
113
- /** An explicitly-off OsSandbox: same `machine()` API, plain LocalMachines. */
113
+ /** An explicitly-off OsSandbox: same `environment()` API, plain LocalEnvironments. */
114
114
  static disabled(reason = "disabled by host") {
115
115
  return new OsSandbox({ enabled: false, reason });
116
116
  }
117
117
  /**
118
- * Build the machine a session should get — sandboxed when this OsSandbox is
119
- * enabled, a plain LocalMachine otherwise. Accepts exactly what LocalMachine's
118
+ * Build the environment a session should get — sandboxed when this OsSandbox is
119
+ * enabled, a plain LocalEnvironment otherwise. Accepts exactly what LocalEnvironment's
120
120
  * constructor does.
121
121
  */
122
- machine(cwdOrOptions = process.cwd()) {
122
+ environment(cwdOrOptions = process.cwd()) {
123
123
  return this.policy === undefined
124
- ? new LocalMachine(cwdOrOptions)
125
- : new SandboxedLocalMachine(this.policy, cwdOrOptions);
124
+ ? new LocalEnvironment(cwdOrOptions)
125
+ : new SandboxedLocalEnvironment(this.policy, cwdOrOptions);
126
126
  }
127
127
  /** Tear down the srt session (filter proxies, monitors). Idempotent. */
128
128
  async dispose() {
@@ -1,10 +1,10 @@
1
1
  /**
2
2
  * srt's wrap API takes a SHELL COMMAND STRING (plus the shell to run it with),
3
- * while Machine.run hands us an argv. This module converts losslessly between
3
+ * while Environment.run hands us an argv. This module converts losslessly between
4
4
  * the two shapes so the sandbox always sees the exact command that would have
5
5
  * run without it.
6
6
  */
7
- /** Single-quote for a POSIX shell (same contract as BaseMachine's internal helper). */
7
+ /** Single-quote for a POSIX shell (same contract as BaseEnvironment's internal helper). */
8
8
  export declare function shellQuoteArg(value: string): string;
9
9
  export interface SrtInvocation {
10
10
  /** The command string to hand srt. */
@@ -13,9 +13,9 @@ export interface SrtInvocation {
13
13
  readonly binShell: string;
14
14
  }
15
15
  /**
16
- * Two argv shapes reach a machine:
16
+ * Two argv shapes reach an environment:
17
17
  *
18
- * - `[shell, "-c", script]` — the bash tool, user hooks, and BaseMachine's own
18
+ * - `[shell, "-c", script]` — the bash tool, user hooks, and BaseEnvironment's own
19
19
  * cwd fallback all build this. Pass `script` through VERBATIM with its own
20
20
  * shell, so quoting inside the script survives untouched.
21
21
  * - anything else (a search binary and its args) — quote each argument into a
@@ -1,10 +1,10 @@
1
1
  /**
2
2
  * srt's wrap API takes a SHELL COMMAND STRING (plus the shell to run it with),
3
- * while Machine.run hands us an argv. This module converts losslessly between
3
+ * while Environment.run hands us an argv. This module converts losslessly between
4
4
  * the two shapes so the sandbox always sees the exact command that would have
5
5
  * run without it.
6
6
  */
7
- /** Single-quote for a POSIX shell (same contract as BaseMachine's internal helper). */
7
+ /** Single-quote for a POSIX shell (same contract as BaseEnvironment's internal helper). */
8
8
  export function shellQuoteArg(value) {
9
9
  if (/^[A-Za-z0-9_/@%+=:,.-]+$/.test(value))
10
10
  return value;
@@ -16,9 +16,9 @@ function isShellPath(candidate) {
16
16
  return SHELL_BASENAMES.has(base);
17
17
  }
18
18
  /**
19
- * Two argv shapes reach a machine:
19
+ * Two argv shapes reach an environment:
20
20
  *
21
- * - `[shell, "-c", script]` — the bash tool, user hooks, and BaseMachine's own
21
+ * - `[shell, "-c", script]` — the bash tool, user hooks, and BaseEnvironment's own
22
22
  * cwd fallback all build this. Pass `script` through VERBATIM with its own
23
23
  * shell, so quoting inside the script survives untouched.
24
24
  * - anything else (a search binary and its args) — quote each argument into a
package/dist/types.d.ts CHANGED
@@ -38,7 +38,7 @@ export interface OsSandboxFilesystemOptions {
38
38
  */
39
39
  readonly denyRead?: readonly string[];
40
40
  /**
41
- * Extra write roots granted to EVERY machine, on top of the per-machine
41
+ * Extra write roots granted to EVERY environment, on top of the per-environment
42
42
  * grant (its cwd + additionalDirs) and the shared system roots (tmp, the
43
43
  * framework's background-task log directory).
44
44
  */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "operon-os-sandbox",
3
- "version": "0.1.0-alpha.2",
4
- "description": "OS-level command sandboxing for the LocalMachine: every Machine.run is wrapped in the platform sandbox (macOS Seatbelt / Linux bubblewrap, via @anthropic-ai/sandbox-runtime) with workspace-scoped write access, domain-allowlist networking, and sandbox-denial annotation on stderr. Unsupported platforms and missing dependencies degrade to a plain LocalMachine.",
3
+ "version": "0.1.0-alpha.20",
4
+ "description": "OS-level command sandboxing for the LocalEnvironment: every Environment.run is wrapped in the platform sandbox (macOS Seatbelt / Linux bubblewrap, via @anthropic-ai/sandbox-runtime) with workspace-scoped write access, domain-allowlist networking, and sandbox-denial annotation on stderr. Unsupported platforms and missing dependencies degrade to a plain LocalEnvironment.",
5
5
  "type": "module",
6
6
  "engines": {
7
7
  "node": ">=22"
@@ -26,7 +26,7 @@
26
26
  },
27
27
  "dependencies": {
28
28
  "@anthropic-ai/sandbox-runtime": "0.0.73",
29
- "operon-agents-core": "0.1.0-alpha.2"
29
+ "operon-agents-core": "0.1.0-alpha.20"
30
30
  },
31
31
  "files": [
32
32
  "dist",