Skip to content

Commit 3fa3276

Browse files
authored
feat(nodes): opt-in container isolation for node-hosted worker sessions (#128447)
* feat(nodes): opt-in container isolation for node-hosted worker sessions nodeHost.workerRuns.isolation=container runs each worker session inside a Docker-compatible container (docker/OrbStack/podman): stdio launch transport, exactly two bind mounts (bundle read-only, workspace read-write), allowlisted env, and the container itself as the durable launch identity — created stopped and journaled before the descriptor is delivered, killed/removed on cancel, fence, shutdown, and recovery, with an owned-orphan sweep at startup. Missing or changed engines disable hosting with an explicit diagnostic instead of falling back to bare processes. Additive nullable worker_container_json column on node_worker_launches (schema version unchanged). * fix(test): base-shape fixture skips additive columns of stripped tables node_worker_launches is excluded from claw-scoped state schemas, so the read-only compat fixture cannot drop its additive column there; drop only columns whose owning table exists. * fix(test): guard split destructuring in base-shape fixture * test(state): record worker_container_json in the canonical additive-column list * fix(nodes): harden container isolation per review findings - Revalidate the engine daemon target immediately before container creation; a replaced daemon receives zero create/start requests (regression proves it). - A pending launch keeps its worker slot until the journaled container is killed/removed; cancellation cannot free capacity over a live container. - Windows node hosts fail closed at startup for isolation=container with an actionable diagnostic (native paths cannot be container mount targets). - Container identity moves from an additive column to the same-version companion table node_worker_launch_containers (bare STRICT, lazily ensured on first container write, pruned with the launch journal): the launch table is contract-optional and shipped readers reject additive columns there. An exact v9 predecessor now provably opens and uses the journal after the candidate populated container rows.
1 parent 62aca9a commit 3fa3276

31 files changed

Lines changed: 2840 additions & 308 deletions
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"core": 2342,
2+
"core": 2345,
33
"channel": 3584,
4-
"plugin": 3978
4+
"plugin": 3957
55
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ac6fc6872da112e588f289a5bdc713affb7f76c019031a93bdb7a34964a4ce44 config-baseline.json
2-
16f67f4b0b19b3863ee673ec5b5dd86c7d493e433f41ee949857fc6e6d594938 config-baseline.core.json
1+
f8fd5355eea5b750fdd9cd3bd12f7b89dfcd8e48c75d46864e298610d07c98b6 config-baseline.json
2+
2d47989b749e6c98a5b79497b95c7a24d20f17f9aebb06e65982bab093cbbedd config-baseline.core.json
33
3300f931abce160c1d6768af1a358683b8f77af479e8b728aeefd38039a61507 config-baseline.channel.json
4-
ed7c7e8dfe9d676ebbf60b5ee55f72d1f9e0286ffb37743f40f6c337816b166d config-baseline.plugin.json
4+
91f13b695cfae24bff25c09ff8d091f357c13bf01b220c0640216aa5081e4db2 config-baseline.plugin.json

‎docs/nodes/index.md‎

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
summary: "Nodes: pairing, capabilities, permissions, and CLI helpers for camera/screen/device/notifications/system and the macOS widget panel"
33
read_when:
44
- Pairing iOS/watchOS/Android nodes to a gateway
5+
- Enabling isolated OpenClaw session hosting on a paired node
56
- Using node camera or screen capture for agent context
67
- Presenting a hosted widget on a Mac
78
- Adding new node commands or CLI helpers
@@ -559,6 +560,79 @@ failed provider or placement cleanup.
559560
See [Anthropic: Claude sessions across computers](/providers/anthropic#claude-sessions-across-computers)
560561
for the Control UI behavior and storage sources.
561562

563+
#### Isolate hosted worker sessions in containers
564+
565+
By default, hosted OpenClaw worker sessions run directly on the paired node.
566+
Set `nodeHost.workerRuns.isolation` to `"container"` on that node to run each
567+
worker inside its own container instead:
568+
569+
```json5
570+
{
571+
nodeHost: {
572+
workerRuns: {
573+
enabled: true,
574+
isolation: "container",
575+
// Optional: use a digest-pinned, private-registry, or preloaded image.
576+
// containerImage: "registry.example.com/openclaw/node:22-slim",
577+
},
578+
},
579+
}
580+
```
581+
582+
Restart the node host after changing either setting. Isolation defaults to
583+
`"none"`, preserving the existing direct-process behavior. This setting is
584+
enforced locally on the node; the Gateway cannot silently disable it or fall
585+
back to an unisolated worker.
586+
587+
Container isolation is supported on Linux and macOS node hosts; Windows is
588+
unsupported because native Windows paths cannot be mounted at their original
589+
paths inside the container. The node must have a working Docker-compatible
590+
container engine. OpenClaw tries the `docker` CLI first, including Docker-backed
591+
OrbStack installations, and then `podman`. The selected engine and daemon are
592+
checked when the node host starts and again before each container is created.
593+
If the platform is unsupported, neither engine works, or the daemon changes,
594+
session hosting or the affected launch fails visibly instead of falling back to
595+
an unisolated worker. Install or start the engine, verify `docker version` or
596+
`podman version`, and restart the node host.
597+
598+
The default image is `node:22-slim`; the engine pulls it on first use when it
599+
is not already present. Set `nodeHost.workerRuns.containerImage` to choose a
600+
digest-pinned image, a private-registry image, or an image already available
601+
to the engine. The image must provide a working Node.js 22 or newer runtime on
602+
its standard executable search path. If the image cannot be pulled, is
603+
inaccessible, or does not provide a suitable Node.js runtime, that session
604+
launch fails visibly; it never retries as a bare host process. Preload the
605+
image or configure registry access before hosting sessions on an offline or
606+
restricted node.
607+
608+
Each worker container receives only two host bind mounts: its verified worker
609+
bundle root is read-only, and its assigned session workspace is read-write.
610+
Both are mounted at their original absolute host paths so the sealed bundle
611+
and workspace descriptor remain valid; the session workspace is also the
612+
container working directory. OpenClaw passes only the existing frozen,
613+
non-secret worker environment allowlist and adds no other host mounts.
614+
Container isolation protects the rest of the host filesystem and separates
615+
the worker process, but the worker can still modify its assigned workspace
616+
and connect to the Gateway.
617+
618+
The container uses the engine's normal outbound networking and must be able
619+
to reach the Gateway worker WebSocket endpoint. A Gateway address such as
620+
`127.0.0.1` or `localhost` that works on the node host points back into the
621+
container when used by the worker; configure a Gateway address reachable from
622+
the container network instead. If a Gateway requires a custom certificate
623+
authority, `NODE_EXTRA_CA_CERTS` must point to a certificate already inside
624+
the mounted bundle or session workspace; OpenClaw will not mount another host
625+
path for it. Browser assignments that require access to host-only browser
626+
state are not supported in container-isolated sessions.
627+
628+
Cancellation and fencing terminate the container itself rather than only the
629+
container-engine client. The node host records the container's durable engine
630+
and container identity, checks that identity during restart reconciliation,
631+
and removes orphaned worker containers labeled for the same Gateway. If the
632+
node-host process exits unexpectedly, a running container can survive until
633+
the next node-host startup; keep the node host under a restarting service if
634+
that cleanup window must remain short.
635+
562636
### OpenCode and Pi sessions
563637

564638
The bundled OpenCode and ACPX plugins also discover read-only native session

‎docs/plan/runners.md‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,15 @@ stated honestly (revision 1 undersold this):
219219
namespaced by gateway identity so two gateways pairing one machine cannot
220220
corrupt each other's state.
221221

222-
Isolation on node runners: optional worker-in-docker/podman, same sandbox
223-
axis as gateway-local sessions. Cloud leases keep full-permission-within-the-
224-
box (the machine is the boundary).
222+
Node runners can opt into per-worker Docker-compatible container isolation
223+
with `nodeHost.workerRuns.isolation: "container"`; the default `"none"`
224+
preserves direct host execution. The node resolves its engine at startup,
225+
fails closed when the requested boundary is unavailable, and owns durable
226+
container identity, cancellation, restart reconciliation, and orphan cleanup.
227+
The verified bundle remains read-only, the session workspace remains writable,
228+
and both retain their exact host paths inside the container. This is the same
229+
isolation axis as gateway-local sessions, not a separate placement type. Cloud
230+
leases keep full-permission-within-the-box because the machine is the boundary.
225231

226232
Milestone 6 now has the public worker ingress, transport-neutral launch
227233
descriptor, durable node-host supervisor, private launch/status/cancel dialect,
@@ -245,8 +251,8 @@ and then removes retired generations, transfer siblings, unreachable manifests,
245251
and empty workspace parents in bounded passes. The Gateway bundle producer
246252
also prunes unreferenced local tarballs only after a successful current build,
247253
while preserving hashes named by durable environments and placements. Durable
248-
offline recovery is complete; isolation and checkout ownership remain milestone
249-
6 work.
254+
offline recovery and opt-in container isolation are complete; checkout
255+
ownership remains milestone 6 work.
250256

251257
### Trust model (operator-decided, v1)
252258

@@ -518,7 +524,8 @@ Independently mergeable PR series; 3–5 can interleave after 1c.
518524
admission; invalid attempts are cheap and unenumerable.
519525
6. **Node worker provider**: lease union, dispatch target union, node tunnel
520526
handle, durable supervised launch, HTTPS delta sync + origin fetch,
521-
tri-state inspect + reaper + GC, concurrency slots, `runner-offline`
527+
tri-state inspect + reaper + GC, concurrency slots, opt-in container
528+
isolation with durable container lifecycle reconciliation, `runner-offline`
522529
placement semantics, gateway-namespaced install root, approver-provenance
523530
column. Fault-injection tests gate exit: device sleep mid-turn, node WS
524531
blip mid-turn (turn survives), gateway restart with offline device,

‎src/claws/read-only-state-compat.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,18 @@ function createBaseShapeState(params: {
4242
for (const column of OPENCLAW_STATE_MAINTENANCE_SCHEMA_COMPATIBILITY.allowedMissingColumns ??
4343
[]) {
4444
const [table, name] = column.split(".");
45+
if (!table || !name) {
46+
continue;
47+
}
48+
// Additive columns can belong to tables that are stripped from claw-scoped
49+
// schemas entirely (e.g. node_worker_launches); base shape only drops
50+
// columns whose owning table exists here.
51+
const tableExists = database.db
52+
.prepare(`SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?`)
53+
.get(table);
54+
if (!tableExists) {
55+
continue;
56+
}
4557
database.db.exec(`ALTER TABLE ${table} DROP COLUMN ${name};`);
4658
}
4759
closeOpenClawStateDatabaseForTest();

‎src/config/config.node-agent-runs.test.ts‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,48 @@ describe("node agent-runs config", () => {
3232
expect(validateConfigObject({ nodeHost: { workerRuns: { enabled } } }).ok).toBe(true);
3333
});
3434

35+
it("keeps direct worker execution as the implicit default", () => {
36+
const result = validateConfigObject({ nodeHost: { workerRuns: {} } });
37+
expect(result.ok).toBe(true);
38+
if (result.ok) {
39+
expect(result.config.nodeHost?.workerRuns?.isolation).toBeUndefined();
40+
}
41+
});
42+
43+
it.each(["none", "container"])("accepts worker session isolation=%s", (isolation) => {
44+
expect(validateConfigObject({ nodeHost: { workerRuns: { isolation } } }).ok).toBe(true);
45+
});
46+
47+
it.each(["docker", "", true, null])(
48+
"rejects invalid worker session isolation=%j",
49+
(isolation) => {
50+
const result = validateConfigObject({ nodeHost: { workerRuns: { isolation } } });
51+
expect(result.ok).toBe(false);
52+
if (!result.ok) {
53+
expect(result.issues.some((issue) => issue.path === "nodeHost.workerRuns.isolation")).toBe(
54+
true,
55+
);
56+
}
57+
},
58+
);
59+
60+
it.each(["node:22-slim", `registry.example.test/workers/node@sha256:${"a".repeat(64)}`])(
61+
"accepts worker container image=%s",
62+
(containerImage) => {
63+
expect(validateConfigObject({ nodeHost: { workerRuns: { containerImage } } }).ok).toBe(true);
64+
},
65+
);
66+
67+
it.each(["", " ", 22, null])("rejects invalid worker container image=%j", (containerImage) => {
68+
const result = validateConfigObject({ nodeHost: { workerRuns: { containerImage } } });
69+
expect(result.ok).toBe(false);
70+
if (!result.ok) {
71+
expect(
72+
result.issues.some((issue) => issue.path === "nodeHost.workerRuns.containerImage"),
73+
).toBe(true);
74+
}
75+
});
76+
3577
it.each([1, 5, 1024])("accepts worker session hosting capacity=%s", (capacity) => {
3678
expect(validateConfigObject({ nodeHost: { workerRuns: { capacity } } }).ok).toBe(true);
3779
});

‎src/config/schema.help.quality.test-fixtures.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ export const TARGET_KEYS = [
135135
"nodeHost.agentRuns.claude.enabled",
136136
"nodeHost.workerRuns",
137137
"nodeHost.workerRuns.enabled",
138+
"nodeHost.workerRuns.isolation",
139+
"nodeHost.workerRuns.containerImage",
138140
"nodeHost.browserProxy",
139141
"nodeHost.browserProxy.enabled",
140142
"nodeHost.browserProxy.allowProfiles",
@@ -343,6 +345,7 @@ export const ENUM_EXPECTATIONS: Record<string, string[]> = {
343345
"models.mode": ['"merge"', '"replace"'],
344346
"models.providers.*.auth": ['"api-key"', '"token"', '"oauth"', '"aws-sdk"'],
345347
"gateway.reload.mode": ['"off"', '"hybrid"'],
348+
"nodeHost.workerRuns.isolation": ['"none"', '"container"'],
346349
"approvals.exec.mode": ['"session"', '"targets"', '"both"'],
347350
"bindings[].match.peer.kind": ['"direct"', '"group"', '"channel"', '"dm"'],
348351
"broadcast.strategy": ['"parallel"', '"sequential"'],

‎src/config/schema.help.runtime.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,10 @@ export const RUNTIME_FIELD_HELP: Record<string, string> = {
286286
"Allow this paired node to host sessions from exact bundles installed by its Gateway (default: false).",
287287
"nodeHost.workerRuns.capacity":
288288
"Maximum concurrent worker sessions hosted by this node (default: the number of available CPU cores). Must be an integer from 1 through 1024.",
289+
"nodeHost.workerRuns.isolation":
290+
'Select the worker-session process boundary: "none" runs directly on the node host (default); "container" requires a working Docker-compatible engine and never falls back to host execution.',
291+
"nodeHost.workerRuns.containerImage":
292+
'Optional Node 22+ image for container-isolated workers (default: "node:22-slim"). Use a digest-pinned, private-registry, or preloaded image when needed; missing images are pulled on first use.',
289293
"nodeHost.browserProxy":
290294
"Groups browser-proxy settings for exposing local browser control through node routing. Enable only when remote node workflows need your local browser profiles.",
291295
"nodeHost.browserProxy.enabled":

‎src/config/schema.labels.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,8 @@ export const FIELD_LABELS: Record<string, string> = {
413413
"nodeHost.workerRuns": "Node Worker Runs",
414414
"nodeHost.workerRuns.enabled": "Node Worker Runs Enabled",
415415
"nodeHost.workerRuns.capacity": "Node Worker Run Capacity",
416+
"nodeHost.workerRuns.isolation": "Node Worker Run Isolation",
417+
"nodeHost.workerRuns.containerImage": "Node Worker Run Container Image",
416418
"nodeHost.browserProxy": "Node Browser Proxy",
417419
"nodeHost.browserProxy.enabled": "Node Browser Proxy Enabled",
418420
"nodeHost.browserProxy.allowProfiles": "Node Browser Proxy Allowed Profiles",

‎src/config/schema.tags.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ const TAG_OVERRIDES: Record<string, ConfigTag[]> = {
6868
"gateway.nodes.allowSkills": ["tools", "security", "access", "network", "advanced"],
6969
"nodeHost.agentRuns.claude.enabled": ["tools", "security", "access", "network", "advanced"],
7070
"nodeHost.workerRuns.enabled": ["tools", "security", "access", "network", "advanced"],
71+
"nodeHost.workerRuns.isolation": ["security", "access", "advanced"],
72+
"nodeHost.workerRuns.containerImage": ["security", "network", "advanced"],
7173
"nodeHost.mcp.servers": ["tools", "network", "advanced"],
7274
"nodeHost.skills.enabled": ["tools", "network", "advanced"],
7375
"proxy.tls.caFile": ["security", "network", "storage", "advanced"],

0 commit comments

Comments
 (0)