Skip to content

0085 — Managed Node.js runtime, provisioned on demand ​

  • Status: accepted
  • Date: 2026-07-17
  • Deciders: Josh, agent

1. Context & problem statement ​

A whole class of protoAgent extensions launches through Node's npx: the ACP coding agents driven via the fetch form (npx -y @agentclientprotocol/claude-agent-acp for Claude Code, npx -y @zed-industries/codex-acp for Codex — runtime/acp_agents.py), and most of the community MCP servers in config/mcp-catalog.json. All of them need node/npx on the PATH of the process that spawns them.

The desktop app doesn't provide one. It bundles only the Python server sidecar (tauri.conf.json externalBin), and the existing PATH machinery — augmented_sidecar_path() in the Tauri shell (#1299) and acp_client._discovered_node_dirs() on the Python side — can only find a Node the user already installed (Homebrew, nvm, fnm, Volta, asdf). On a clean machine with no developer toolchain there is nothing to find, so those features dead-end with "agent binary not found: 'npx'". A desktop user reasonably expects "npx functionality" to work on download without hand-installing Node into their shell.

The default experience does not need Node — the native runtime is the LangGraph loop talking to the LiteLLM gateway, entirely inside the Python sidecar. Node is an opt-in advanced dependency (ACP coding agents + npx MCP servers). So the bar isn't "the app is broken", it's "an opt-in capability silently requires a toolchain the user doesn't have, and fails opaquely".

2. Decision drivers ​

  • Meet the "works on download" expectation for the npx-based features without making every user pay for a runtime they may never use.
  • Keep the installer lean and side-step signing/notarizing a second bundled Mach-O binary inside the hardened-runtime app.
  • One consumption seam, not a patch at every subprocess launch site — ACP (acp_client._launch_env) and MCP (mcp_tools._inherited_env) build their child env independently today, and future spawn sites shouldn't have to know.
  • A real integrity gate on a downloaded, executed runtime — not trust-on-first-use.
  • Respect the import-layering invariant: infra/runtime must not reach into server/operator_api.

3. Considered options ​

  1. Bundle Node in the desktop app — ship a Node runtime as a second Tauri sidecar. Most literal answer, but grows every installer by the runtime, adds a binary to sign/notarize per platform, and pays the cost for users who never touch the feature.
  2. Bundle Node + pre-install the adapters — fully offline, but 100 MB+ (the Claude adapter carries the whole Code SDK) and makes us own those adapters' version + security cadence, adjacent to the "don't vendor Anthropic assets" line we already hold.
  3. Provision on demand (chosen) — download a pinned Node into the box-shared data dir when the user asks for it (one CLI command / one console click), and teach the existing PATH seam about it. Lean installer, no bundled binary to notarize, we control the exact version. Costs a one-time download when the user opts in.

4. Decision ​

Adopt option 3.

Where it lives. The runtime is extracted to box_root/runtime/node/current (box tier, not instance tier — one machine provisions Node once and the default instance, the dev sandbox, and every fleet member share it; a per-instance copy would waste ~150 MB each and re-download on every dev-reset). current/ is a real directory (not a symlink — Windows symlink creation needs elevation), so consumers resolve current/bin (POSIX) / current (Windows) without knowing the pinned version.

Two halves, split by layer.

  • infra/node_runtime.py — the light, dependency-free half every layer may import: managed_node_bin_dir() (the bin dir of a working install, else None) and augment_path_with_managed_node(), the single consumption seam.
  • runtime/node_install.py — the installer: download a pinned release from nodejs.org, verify it against an in-repo SHA256 table, extract, and swap it into current/ (old install kept until the new one is in place). Consumed by the CLI and, later, an operator endpoint.

The consumption seam is a boot-time PATH append. At server start (server.agent_init) we call augment_path_with_managed_node(): if node isn't already resolvable and a managed install exists, we append its bin dir to the process os.environ["PATH"]. Append (not prepend) so a user's own Node always wins; process-level (not per-launch) so ACP, MCP, delegates, and gh/git inherit it uniformly. The installer re-runs the same augmentation on success, so a live server hot-adopts a freshly provisioned runtime without a restart.

Integrity. We pin NODE_VERSION and a SHA256 per supported (platform, arch) in _SHA256, checked in from https://nodejs.org/dist/<version>/SHASUMS256.txt. Verifying against a digest we already committed — rather than the SHASUMS256.txt the same host serves — is what makes this a real gate: a compromised mirror can't swap the binary without also matching a hash in the repo. Archive members are additionally guarded against absolute/.. paths, and tar extraction uses filter='data' where available.

Surfaces. protoagent runtime install-node provisions it; runtime list shows Node status (system / managed / not-found) and reflects the managed runtime in the per-agent install probes. Supported targets: darwin arm64/x64, linux arm64/x64, win x64. A one-click console button + operator endpoint is a follow-up.

5. Consequences ​

  • Positive. The npx-based coding agents and MCP servers work on a clean desktop machine after one opt-in step; installer stays lean; no second binary to notarize; the version is ours to pin and bump; one seam covers every current and future subprocess launch.
  • Negative / trade-offs. The first use still needs network (the Node download, and npx -y still fetches the adapter on first launch, then caches in ~/.npm/_npx); bumping Node means updating NODE_VERSION and the _SHA256 table together; the on-demand step is a real (if one-time) wait, not invisible.
  • Not chosen. We do not vendor the ACP adapters — npx -y fetch-on-demand keeps us out of owning the Claude/Codex SDK release cadence.

Amendment 2026-10-15: plugins declare Node; version-aware resolution (#4238) ​

Problem. Three gaps surfaced once plugins started shipping Node code (the Atlas LikeC4 viewer vendors a single-file engine that needs Node 20 or newer):

  1. Any node on PATH won, whatever its version. The PATH seam only appended the managed runtime when no Node resolved, so a user's Node 18 shadowed a working managed Node 24, and a plugin needing Node 20 failed at runtime with no warning.
  2. Plugins couldn't declare a Node requirement. Each one hand-rolled a preflight, only mentioned it in its description, or shipped a private shim.
  3. There was no shared resolver. The nvm / fnm / Volta / asdf / nodenv / Homebrew discovery lived privately in plugins/coding_agent/acp_client.py.

Decision. This amendment changes four things:

  1. One resolver. infra/node_runtime.py owns discovery (discovered_node_dirs, moved from the ACP client, which now imports it), version probing (node_version(exe), which runs exe --version with a timeout and caches by path, mtime and size), and resolve_node(min_version) -> NodeResolution(path, version, source) | None. The order is the PATH node if it satisfies the floor, then discovered installs (newest first), then the managed runtime. It always returns an absolute path.
  2. SDK. sdk.node_executable(min_version=None) -> Path | None is the plugin-facing seam over resolve_node. Plugins spawn the absolute path it returns, never a bare "node".
  3. Version-aware PATH. CORE_NODE_FLOOR = "20". When the PATH node meets the floor, or its version can't be read, the user's Node still wins and PATH is untouched. When it is older than the floor and a managed install exists, augment_path_with_managed_node() prepends the managed bin dir, logs that once, and stays idempotent. With no PATH node it appends, as before. Setting PROTOAGENT_NODE_SHADOW=0 opts out of the prepend: the old PATH Node stays first, and the below-floor condition is still logged once.
  4. Manifest + deps gate. requires_runtimes: {node: ">=20"} takes only node for now, and the spec is a floor: >=N, >=N.N or >=N.N.N. A bare 20, a YAML int 20 or "v20" means >=20 and is normalized to it. A malformed spec or an unknown runtime logs a warning and is ignored; it doesn't fail the manifest. On every load, an enabled plugin whose requirement resolve_node can't meet gets a runtime-missing setup gap with a new closed action kind, install_node. That button POSTs the existing /api/runtime/node/install. The action is offered only when this platform has a managed build and the pinned version meets the floor. When the install lands, the route runs loader.refresh_runtime_gaps(), which re-checks every plugin with an active gap, so the banner clears without a reload. Each re-report carries the plugin's setup-gap generation, so a plugin disabled during the refresh can't get its banner back. Installing from the CLI instead (protoagent runtime install-node) runs in another process, so the banner says a restart or plugin reload is needed for the running server to pick it up. The gap is separate from deps-missing because that gap's fix is pip, and deps_missing must never carry a runtime name.

Guidance for plugin authors. Ship a vendored single-file JS bundle (esbuild or Rollup output committed with the plugin) and run it as [<absolute node>, bundle.mjs, …] using sdk.node_executable(...). Never run npx at runtime and never run a plugin-owned npm install. Both reach the network at tool-call time, depend on a registry being up, and run unreviewed install scripts on the operator's machine.

Docker. Keep downloading on demand. In the container the box root is /sandbox, so the runtime lands in /sandbox/runtime/node and the existing /sandbox volume keeps it. Preinstalling Node at build time through an optional WITH_NODE build arg, for offline images, is a possible future addition and isn't built yet.

Consequences. A stale PATH Node no longer breaks Node-using features when a managed runtime is present. Plugins get a declared requirement, a standard banner and a one-click fix instead of private shims. The cost is that resolution now runs node --version once per distinct binary per process. The cache keeps that off the hot path.

Amendment 2026-11-08: plugins declare Python; a per-plugin uv venv (#4807) ​

Problem. A plugin that ships Python compute (a document pipeline, a heavy numeric or ML dependency) has nowhere isolated to put it. requires_pip installs into the host or the ADR 0094 managed runtime's shared site-packages, so two plugins can collide on versions and every heavy dep risks loading into the frozen host — exactly what ADR 0093 / 0058 D2's frozen-host gate is there to prevent. Node already had a declared, provisioned-on-demand runtime (the 2026-10-15 amendment); Python did not.

Decision. requires_runtimes grows a second key, python, parsed in graph/plugins/manifest.py beside node. Four points:

  1. Schema. Unlike node's scalar version floor, python takes a mapping:

    yaml
    requires_runtimes:
      python:
        version: "3.12"            # a "N.N" string — the floor uv's --python understands
        requirements:              # a list of PEP 508 specs (may be empty, may be absent)
          - "pandas>=2"

    It normalizes to {"version": "3.12", "requirements": [...]}. version must be a N.N string (a YAML float would silently drop a trailing zero — 3.10 → 3.1). A non-mapping value, a non-N.N version, or a non-list requirements warns and is dropped; the load never fails — the same leniency as node and as requires_pip. Node parsing is unchanged, and the field now holds node's normalized string or python's normalized dict, keyed by runtime (.get("node") → str, .get("python") → dict).

  2. Per-plugin venv, provisioned with uv, never in-process. The host provisions a venv at <plugin_store>/.venv (infra/python_runtime.py: plugin_venv_dir, provision_plugin_venv) by running uv venv --python <version> then uv pip install, and records a marker (version + a hash of requirements) inside the venv so a later load can tell a satisfying venv from a stale one without spawning anything. This keeps ADR 0027's install ≠ code exec rule — provisioning runs only on the operator's Install click, never on load — and honours ADR 0093 / 0058 D2's frozen-host gate, because a plugin's heavy deps live in its own venv and never load into the host process. A documented override, PROTOAGENT_PLUGIN_PYTHON_<ID>, points a plugin's venv at a prepared directory for tests and CI fixtures. (The spawn seam that runs this venv — sdk.plugin_python / sdk.worker — is part 2 of #4807.)

  3. The existing runtime-missing gap, with an Install action. An unmet python runtime — no venv, a wrong version, or a requirements hash that differs from the manifest — reuses loader.RUNTIME_GAP_KEY (the same banner as node), reported by the same _report_runtime_gap on every load. Its fix is a new closed action kind, install_python, whose target is forced to the reporting plugin (a plugin can only ever provision its own venv, like install_deps); the console POSTs the operator-only /api/plugins/install-python with that plugin id. The route rechecks source consent and runs loader.install_plugin_python, which calls provision_plugin_venv and then re-reports the gap so the banner clears without a reload. The button is offered only when uv is present — the same shape as install_node being offered only when a managed build can help. A met venv clears the gap; loading only ever checks.

  4. requires_pip keeps its meaning and its scope. It is still the plugin's declared pip deps for the host / managed runtime, installed by install-deps; it is unchanged by this amendment. requires_runtimes.python is the separate "this plugin wants its own isolated interpreter + deps" declaration, and deps_missing (what Install deps hands to pip) still never carries a runtime name.

Consequences. A Python-heavy plugin gets an isolated, versioned interpreter with its own deps, provisioned by one click, with no risk of colliding with another plugin or loading into the frozen host. The cost mirrors node's: a one-time (if real) uv download/build when the operator opts in, and a uv dependency on the host for that step.

6. References ​

  • ADR 0024 / 0025 — CLI coding agents over ACP; the unified delegate registry.
  • ADR 0033 — ACP-as-runtime.
  • ADR 0004 — instance/box path scoping (infra/paths.py).
  • #1299 — the Tauri sidecar login-shell PATH fix (finds an existing Node; this ADR provides one when none exists).
  • docs/guides/coding-agents.md, docs/guides/mcp.md.

Part of the protoLabs autonomous development studio.