@arcforge/types 2.0.83 → 2.0.85

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcforge/types",
3
- "version": "2.0.83",
3
+ "version": "2.0.85",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "main": "./src/index.ts",
@@ -33,10 +33,9 @@ export type CapsuleTool =
33
33
 
34
34
  /**
35
35
  * Everything the capsule is built from. `env` merges onto the host's
36
- * inherited environment (the trust boundary is the OS-level axon-runner,
37
- * not env isolation) — secret stripping is the caller's compile step, not
36
+ * inherited environment — secret stripping is the caller's compile step, not
38
37
  * capsule behavior. `cwd` is where it lives, `tools` is its entire scope,
39
- * `policy` is what it may do.
38
+ * `policy` is what it may do (mediator + OS confinement, see CapsulePolicy).
40
39
  *
41
40
  * Capsule(config) wires; capsule.boot() spawns.
42
41
  */
@@ -53,18 +52,9 @@ export type CapsuleBlueprint = {
53
52
  /** Tools loaded into global scope before boot() resolves. */
54
53
  tools: CapsuleTool[]
55
54
 
56
- /** What the sandbox may do — enforced by the in-process mediator. */
55
+ /** What the sandbox may do — mediator gates + OS confinement (see CapsulePolicy). */
57
56
  policy: CapsulePolicy
58
57
 
59
- /**
60
- * OS-level enforcement (Linux only). Runs the subprocess as this user via
61
- * the setuid axon-runner and applies fs ACLs derived from the policy.
62
- * Omit to run as the invoking user with mediator enforcement only.
63
- */
64
- userspace?: {
65
- user: string
66
- }
67
-
68
58
  /**
69
59
  * Answer policy escalations. One callback, one decision — default deny.
70
60
  * Called when the mediator hits an "escalate" rule.
@@ -88,8 +78,8 @@ export type CapsuleBlueprint = {
88
78
 
89
79
  /**
90
80
  * Override the default `bun run <entrypoint>` spawn. Used by tests and
91
- * by userspace enforcement (axon-runner substitution is internal —
92
- * callers normally never set this).
81
+ * internally by OS confinement (the bwrap/systemd wrapper is composed by
82
+ * the capsule — callers normally never set this).
93
83
  */
94
84
  spawn?: {
95
85
  command: string
package/src/handle.ts CHANGED
@@ -120,8 +120,13 @@ export type AxonHandle = {
120
120
  /** Installed tool namespaces, callable by name — each call is a mediated capsule request. */
121
121
  tools: Record<string, Record<string, (...args: unknown[]) => Promise<unknown>>>
122
122
 
123
- /** Hot-reload trigger — apply a partial blueprint to the live runtime. */
124
- update(partial: AxonPartialBlueprint): Promise<void>
123
+ /**
124
+ * Hot-reload trigger — apply a blueprint to the live runtime.
125
+ * - mode "merge" (default): partial update; absent fields keep their value.
126
+ * - mode "replace": the blueprint is authoritative (a config-file reload);
127
+ * absent config fields are dropped, not retained.
128
+ */
129
+ update(partial: AxonPartialBlueprint, opts?: { mode?: "merge" | "replace" }): Promise<void>
125
130
 
126
131
  hooks: AxonHooksSurface
127
132
 
package/src/policy.ts CHANGED
@@ -25,38 +25,86 @@ export type PolicyRule =
25
25
  * Capsule-level wire type. Describes what the sandbox subprocess is allowed to
26
26
  * do. Passed directly to the capsule on boot or via `capsule.update()`.
27
27
  *
28
- * Deliberately minimal: two real primitives (process.run/process.spawn),
29
- * a generic per-namespace tools bucket, and generic network destinations.
30
- * Filesystem access has no built-in mediation — it is only ever reachable
31
- * through a tools: entry, so it is gated the same way any other tool is.
28
+ * Two enforcement surfaces, one policy:
29
+ *
30
+ * - The MEDIATOR (all platforms) gates declared tool calls and
31
+ * process.run/process.spawn by glob — the soft layer: typed denials,
32
+ * escalation, span events. It owns `tools` and `process.{run,spawn}`.
33
+ * - OS CONFINEMENT (Linux) is the wall: `fs` becomes mount-namespace bind
34
+ * mounts, `network` becomes a net-namespace + nft allowlist, `limits`
35
+ * becomes cgroup caps. Where the two overlap (network), the OS layer is
36
+ * the truth and the mediator is only the polite error in front of it.
37
+ *
38
+ * `isolation` decides whether the OS wall exists at all.
32
39
  */
33
40
  export type CapsulePolicy = {
34
41
  /**
35
- * OS user to run the capsule subprocess as. Linux only.
42
+ * OS confinement tier. Linux only; a no-op elsewhere (mediator still runs).
43
+ *
44
+ * The tiers map to what the occupant is and who's running it:
45
+ *
46
+ * - `"none"` — no OS wall. The subprocess runs as the invoking user with
47
+ * mediator enforcement only. This is what "I didn't set a security policy"
48
+ * means: a personal agent with full access to your machine, zero hassle,
49
+ * zero host dependencies. The default when no fs/network/limits is set.
36
50
  *
37
- * - `"inherit"` (default) — runs as the invoking user, no OS enforcement.
38
- * - `"axon-agent"` or any username — subprocess and all its children run as
39
- * that user. Filesystem ACLs derived from `fs` policy are applied at boot.
40
- * Requires `axon install` to have been run on the host.
41
- * - `"root"` — valid explicit opt-in; ACLs are skipped (root bypasses them),
42
- * mediator gates and env stripping still apply.
51
+ * - `"auto"` — rootless containment. A bubblewrap box gives the subprocess
52
+ * (and every child) its own filesystem view (only declared paths exist),
53
+ * pid namespace, network on/off, and cgroup resource caps via
54
+ * `systemd-run --user`. Runs as the invoking user — isolation is by
55
+ * namespace, not by a second uid — so it needs NO privilege, NO password,
56
+ * NO `axon install`. This is the "don't read my keys / only this folder"
57
+ * tier: light security that just works. The default when any
58
+ * fs/network/limits policy is set.
43
59
  *
44
- * Hard error at boot if the requested user does not exist on the system.
60
+ * - `"hardened"` — privileged containment. Everything in `"auto"` plus a
61
+ * dedicated unprivileged OS user (true uid separation), system cgroups,
62
+ * and kernel network allowlisting. This is the org / VPS / untrusted-agent
63
+ * tier. Requires `axon install` (one-time root setup) and a privileged
64
+ * helper at runtime; a missing primitive is a hard boot error, never a
65
+ * silent downgrade. Explicit opt-in only — never defaulted into.
66
+ */
67
+ isolation?: "none" | "auto" | "hardened"
68
+
69
+ /**
70
+ * Filesystem view, enforced by the mount namespace under `isolation: "auto"`.
71
+ * Paths outside these grants do not exist inside the box — a forbidden read
72
+ * fails as "no such file", not "permission denied". The capsule cwd and the
73
+ * runtime are always mounted; these extend that. Ignored under `"none"`.
45
74
  */
46
- user?: "inherit" | "root" | (string & {})
75
+ fs?: {
76
+ /** Extra paths mounted read-only. */
77
+ read?: string[]
78
+ /** Paths mounted read-write. */
79
+ write?: string[]
80
+ }
47
81
 
48
- // glob pattern key
82
+ /**
83
+ * Network destinations, keyed by glob. Under `isolation: "auto"` this is
84
+ * enforced in the kernel: the box has its own net namespace and an nft
85
+ * allowlist, so only matching `host:port` destinations are reachable — a
86
+ * raw socket cannot bypass it. The mediator mirrors these rules for typed
87
+ * denials/escalation. Absent = no network at all.
88
+ */
49
89
  network?: Record<string, PolicyRule>
50
90
 
51
91
  process: {
52
92
  spawn: PolicyRule
53
93
  run: PolicyRule
94
+ }
54
95
 
55
- /** Max heap, in MB. Default 5000. */
56
- memory: number
57
-
58
- /** Max CPU, as a percent of one core. Default 100. */
59
- cpu: number
96
+ /**
97
+ * OS resource caps, enforced as a systemd cgroup scope under
98
+ * `isolation: "auto"`. Limits apply to the whole process tree, so children
99
+ * cannot multiply the budget by spawning helpers. Ignored under `"none"`.
100
+ */
101
+ limits?: {
102
+ /** Hard memory cap (systemd size, e.g. "2G"). OOM-killed on breach. */
103
+ memory?: string
104
+ /** CPU quota as a percent of one core (e.g. "50%" or "200%" for 2 cores). */
105
+ cpu?: string
106
+ /** Max processes/threads in the tree (fork-bomb cap). */
107
+ pids?: number
60
108
  }
61
109
 
62
110
  tools?: Record<string, PolicyRule>