DSH / Atlas
2026-11-04implementedarchitecture

Execution environment - tool I/O and the original resident-daemon decision

执行环境——工具 I/O 与最初的常驻守护进程决策

A tool that needs files or programs on another machine can only run against a Session-wide remote world: the [SSH provider family](../../../../packages/ssh/README.md) replaces `ctx.fs` and `ctx.subprocess` for everything. Each filesystem or process operation then costs one network round trip, so a tool that walks a directory or reads many files pays for every step. A remote environment should also stay small: adding,

English

Problem

A tool that needs files or programs on another machine can only run against a Session-wide remote world: the SSH provider family replaces ctx.fs and ctx.subprocess for everything. Each filesystem or process operation then costs one network round trip, so a tool that walks a directory or reads many files pays for every step. A remote environment should also stay small: adding, removing or updating Harness plugins must not require installing anything new on the remote machine.

Decision

dsh-environment (ctx.environments) splits one tool call into three parts:

  1. Remote I/O: the tool sends the source text of a self-contained function to the execution daemon, which evaluates it in a fresh node:vm context on one of its worker threads, with the remote machine's fs, path, a shell-free exec and basic JavaScript utilities such as timers, Buffer and URL.
  2. Host state: the function reaches host handlers supplied with its definition through env.origin, an RPC back to the main runtime, or the tool changes state after the call returns.
  3. Formatting: the tool's output.render produces model content on the host.

The daemon has no plugin system and no tool-specific code. Each definition ships its own function, so plugin changes never require a daemon update; the daemon is one bundled file needing only Node. The original resident-process decision used a Unix listener, an exclusive startup lock and one replaceable worker per host connection to permit reconnection after a dropped path or blocked run. That process-lifecycle decision is superseded by transport process ownership; the function-I/O and origin-callback decisions remain active. Runs in flight when a connection ends fail and are never replayed.

Providers choose opaque, stable handles and user-facing display names. The registry stores metadata separately from transports and uses one execution protocol for all environments; SSH configuration discovery composes the single-SSH provider, while local execution uses a managed process. Origin callbacks belong to the originating dsh and to the connection that owns each run.

Registry changes carry no payload

The registry emits environments/change after each registration and each effective unregistration, once list() and the connection cache reflect it. The event carries no handle or kind: a listener may register or remove environments itself, which emits nested events before the outer event reaches later listeners, so consumers re-read list() instead of applying deltas that could arrive out of order. SSH configuration discovery follows changes to the files it reads. It removes an allowlisted alias that is no longer declared, because OpenSSH would resolve the undeclared name as a host name, and keeps the previous aliases when a changed configuration cannot be read, because such a state is usually an edit in progress.

A definition binds everything except the environment and the arguments

ctx.environments.define(fn, { result, handlers }) fixes the function source, its result validation, its origin handlers and their names, and returns a runner that takes an environment handle, arguments, a signal and an optional trust confirmation. Runner handle selection supersedes this note's original binding of the handle to the definition. The names are the handlers object's own property names when defining; a name added later is neither exposed nor served, while each origin call looks its handler up on the object when it arrives, so replacing a handler's function needs no new definition. A caller keeps one definition for every later call. Handlers belong to the definition and receive only the parameters the function sends, so a caller whose handlers need host objects of one call defines per call.

define reads the origin method names once and hashes the source with them: the hash is the SHA-256 digest of the JSON encoding of [source, methods]. The host serves only those names, so the methods the hash covers are the only ones a run can call. A run carries the hash, and carries the definition, its source and method names, only until the connection's daemon has answered a run that carried it; definitions with identical source and handler names in the same order share the entry, while identical source with other handler names, or the same names in another order, is another definition. The daemon verifies each received definition against its hash and keeps it for its connection, and each worker compiles a definition's source once while still evaluating it in a fresh context per run, so caching changes no caller. The cache lives only as long as its connection because every connection starts a fresh daemon. The registry omits a definition once the daemon has answered a run that carried it, with a result or an error: the daemon keeps a verified definition before it runs the function, so only a defect leaves an answered definition unknown, and the daemon refuses a run that names an unknown hash; there is no retry exchange.

Each run occupies a worker thread

One host connection carries the runs of every Session that uses an environment. A function that blocks its thread, such as a backtracking regular expression or a CPU loop, would otherwise stall every run on that connection, and the host would close the connection and with it the other runs and their exec processes. The daemon therefore keeps a pool of worker threads per connection: a run occupies one worker and returns it when the run settles, so the pool grows to the connection's peak concurrency, which maxPending bounds, and closing the connection ends every worker. Cancellation aborts the function's env.signal; if the function has not stopped within half of cancelGraceMs, the daemon terminates its worker and answers the cancellation before the host's deadline, so the connection and its other runs continue. exec, its process-group cleanup and origin calls stay on the main thread, which owns every process the connection starts. The daemon is installed as one file, so each worker starts from the source text of one self-contained function.

Values cross between the main thread and a worker as postMessage structured clones. That algorithm accepts the values the connection's frames accept but copies a Buffer as a Uint8Array, so a Buffer in arguments, results or origin values arrives as a Uint8Array. Errors cross the thread boundary and the connection as their name, message and string code, because structured clone keeps only standard error names and drops code.

An exception that no code catches, such as one thrown in a timer callback, fails the run its worker is serving instead of ending the worker and with it a run that may not have caused it. Between runs, the worker reports such an exception on standard error and keeps serving. A run's timers, including those of AbortSignal.timeout, end with the run, and its abort listeners run as it ends, so only continuations of a finished run's own pending operations can still run during a later run, and an exception they leave uncaught fails that later run.

Transports are plugins

The daemon only needs a byte stream. Providers register environment metadata and a transport with ctx.environments.register(info, transport); each open returns a channel with its security facts and end reason. The shipped SSH transport runs daemon.js serve --stdio directly through OpenSSH; the local transport starts the same entry in a managed Node process. Each new connection starts a fresh daemon, while the registry reuses a live channel and never replays a sent run. Transports own process startup and shutdown; the registry owns the protocol and connection cache. A provider may register several environments, and each run names one contributed handle.

Trust comes from the transport, and the handshake leaves room for more

Anyone who can connect can run code as the daemon user, so channel access determines who can execute. Every connection starts with auth, which negotiates a mechanism and sets the connection's limits. The only mechanism is transport: SSH authenticates user and host, with host keys checked strictly and an unknown key, fetched through ssh so proxies apply, trusted only by a pinned fingerprint or a person's confirmation. The local provider owns its child process and pipes. The original socket-permission trust model is superseded by transport process ownership. There is no network listener. A network transport must authenticate the channel and bind that authentication to it before accepting execution requests.

Requests flow in both directions with cancellation and per-direction maxPending slots. A cancelled request keeps its slot until the other peer answers it, so both peers count the same work; a peer that does not answer a cancellation within cancelGraceMs loses the connection, and the next run reconnects.

Values cross as structured clones in split frames

Each frame is a 4-byte length followed by a node:v8 serialization, so arguments, results and origin values are structured clones. Both peers run supported Node releases, so tools pass file bytes as Uint8Array without base64, keep undefined, Date, Map and bigint, and type arguments with interfaces, while zod still validates every decoded frame. A message larger than maxFrameBytes travels as part frames that the receiver reassembles within the negotiated maxMessageBytes. Parts of different messages interleave, so a cancellation or small origin call waits for at most one frame of a large transfer, and a cancelled transfer stops sending its remaining parts. Error frames carry the thrown error's name, message and string code, so an errno or HarnessError code survives the connection in both directions.

Callers see only the message limit. The registry exposes it as ctx.environments.limits because it is one registry-wide value, negotiated identically for every connection, and functions read the same value as env.limits.

A peer sends messages as parts only while their sizes together fit maxMessageBytes; further ones wait in order, and messages that fit one frame never wait for room. The receiver enforces the same total and requires every part but a message's last to carry at least what a minimum-size frame holds, so reassembly holds at most maxMessageBytes per direction in a bounded number of parts. A request cancelled while it waits has sent nothing and frees its slot at once. A receiver stops counting the answer of a request it cancelled, so a sender can return the room of a stopped answer before its error frame arrives.

Shared peer code

The request peer's cancellation bookkeeping matches the SSH helper peer and carries a jscpd:ignore exception. The SSH peer uses JSON payloads in its length-prefixed frames, UUID ids, per-request-class management limits and SSH-specific diagnostics, and does not split messages, so sharing it would move SSH behavior into a generic package or SSH wording into this one. Extract one peer package when a third consumer needs the same request semantics.

Alternatives considered

  • Remote ctx.fs and ctx.subprocess only. Rejected for tool I/O: every primitive is a round trip, and a tool cannot keep a multi-step operation on the remote machine.
  • A subset of the Harness runtime on the remote machine. Rejected: plugins would need to be installed on the host, the remote machine or both, and the remote runtime would need updating with them.
  • A native daemon with its own plugin interface, restarted on every plugin change. Rejected: it needs a second plugin system, and restarts would interrupt every remote run.
  • A daemon tied to one SSH session's standard input and output. Originally rejected because it exits on disconnection and each transport needs a launch path. This rejection is superseded by transport process ownership, which assigns launch and persistence to transports.
  • Reusing the dsh-ssh helper as the transport. Originally rejected because its connection- or lease-scoped cleanup conflicted with the resident-process decision. Transport process ownership supersedes that resident requirement; a ctx.ssh.connectStream provider remains an independent transport choice.
  • Refusing a second host connection. Originally rejected because a lingering or blocked connection could prevent reconnection. The per-connection process model in transport process ownership supersedes the shared listener's admission decision.
  • Per-call handlers. Handlers could close over the host objects of each call. Rejected by the author: callers with per-call host state define per call. The same rejection originally covered per-call handles; runner handle selection supersedes that part.
  • Evaluating functions on the daemon's main thread. Rejected: the node:vm timeout option bounds only synchronous evaluation, and a blocked main thread stops the protocol and every other run of the connection.
  • A new worker or child process per run. Rejected: each run would pay thread or process startup, and a child process would add a second process tree to supervise. A pool reuses workers while every run still gets a fresh context.
  • A definition cache that outlives its connection. Rejected: every connection starts a fresh daemon, so a longer-lived cache would need daemon-side storage and invalidation.
  • Origin method names in every run. Rejected: define fixes the handler names, so they are part of the definition the connection caches; repeating them in each run adds bytes without adding information.
  • Newline-delimited JSON with base64 for bytes. Rejected: base64 enlarges binary payloads by a third, JSON loses undefined, dates and maps, JSON types reject interfaces, and tools would hand-roll codecs and chunking against a frame limit they cannot see.
  • The message limit in list() or EnvironmentInfo. Rejected: the limit is registry configuration, identical for every environment, while EnvironmentInfo holds provider-contributed metadata.
  • Bounding partially received messages only by pending slots. Rejected: maxPending requests and as many answers of maxMessageBytes each reach 8 GiB per direction with the defaults, and a receiver limit below what senders may send would close connections that follow the protocol.
  • Application-level keys over authenticated channels. Deferred: channel access already permits execution as the daemon user. The original Unix-socket argument also relied on filesystem permissions; transport process ownership removes that deployed mechanism while retaining channel authentication and the extensible auth exchange.

Consequences

  • Tools keep one Harness runtime and one plugin installation; remote code is ordinary JavaScript shipped per run.
  • The shipped source must be self-contained after the host's transpiler runs. The daemon defines a no-op __name for esbuild keepNames output; other transpiler or instrumentation helpers fail at run time.
  • The utilities a run's context supplies, its arguments and the values its env returns come from its worker's realm, so instanceof checks against the context's own intrinsics, such as Uint8Array, can be false for their objects.
  • node:vm separates globals between runs but is not a security boundary: remote code runs with the daemon user's permissions and bypasses ctx.sandbox.
  • EnvironmentValue accepts interfaces and therefore also functions at compile time; structured clone rejects such values when their message is encoded, before anything is sent.
  • Both peers must read each other's node:v8 format version; Node 24 and 26 share version 15.
  • No shipped tool uses the service yet; Bash, file tools and PTC still use the mounted ctx.fs and ctx.subprocess providers.

中文

问题

需要另一台机器上的文件或程序的工具,只能在整个 Session 范围的远程环境中运行:SSH 提供方系列会为所有操作替换 ctx.fs 和 ctx.subprocess。此时每次文件系统或进程操作都需要一次网络往返,因此遍历目录或读取大量文件的工具要为每一步付出这一开销。远程环境也应保持精简:添加、移除或更新 Harness 插件不得要求在远程机器上安装任何新内容。

决策

dsh-environment(ctx.environments)把一次工具调用拆分为三个部分:

  1. 远程 I/O:工具把一个自包含函数的源代码文本发送给执行守护进程,守护进程在其某个 worker 线程上的全新 node:vm 上下文中对其求值,并提供远程机器的 fs、path、不经 shell 的 exec,以及定时器、Buffer 和 URL 等基础 JavaScript 实用 API。
  2. host 状态:该函数通过 env.origin(回到主运行时的 RPC)调用随其定义提供的 host 端处理函数,或由工具在调用返回后修改状态。
  3. 格式化:工具的 output.render 在 host 上生成模型内容。

守护进程没有插件系统,也没有工具专用代码。每个定义都携带自己的函数,因此插件变更从不需要更新守护进程;守护进程是一个只需要 Node 的打包文件。最初的常驻进程决策使用 Unix 监听器、独占启动锁,以及每个 host 连接对应的可替换 worker,以便在网络路径断开或运行阻塞后重新连接。该进程生命周期决策已由传输进程管理取代;函数 I/O 与发起端回调决策仍然有效。连接结束时正在进行的运行会失败,且从不重放。

提供方选择稳定的不透明句柄和面向用户的显示名称。注册表将元数据与传输方式分开存储,并为所有环境使用同一套执行协议;SSH 配置发现组合使用单目标 SSH 提供方,本地执行则使用受管理的进程。发起端回调归属于发起端 dsh,以及各次运行所属的连接。

注册表变化不携带载荷

注册表在每次注册和每次实际生效的注销之后,待 list() 和连接缓存反映该变化时,发出 environments/change。该事件不携带句柄或变化类型:监听器自身可能注册或移除环境,这会在外层事件到达后续监听器之前发出嵌套事件,因此消费方重新读取 list(),而不是应用可能乱序到达的增量。SSH 配置发现会跟随其读取的文件的变化。它会移除允许列表中不再声明的别名,因为 OpenSSH 会把未声明的名称当作主机名解析;变化后的配置无法读取时,它保留之前的别名,因为这种状态通常是编辑尚未完成。

定义绑定除环境和参数以外的所有内容

ctx.environments.define(fn, { result, handlers }) 固定函数源码、其结果校验、发起端处理函数及其名称,并返回一个接受环境句柄、参数、信号和可选信任确认的运行器。运行器选择句柄取代了本记录最初将句柄绑定到定义的决策。这些名称是定义时处理函数对象的自有属性名;之后添加的名称不会成为发起端方法,对它的调用也不会得到处理,而每次发起端调用都在到达时从该对象上查找其处理函数,因此替换某个名称对应的处理函数时无需新建定义。调用方保留一个定义供之后的每次调用使用。处理函数属于定义,且只接收函数发送的参数;因此,如果调用方的处理函数需要某次调用的 host 对象,该调用方就为每次调用分别定义。

define 只读取一次发起端方法名称,并对源码连同这些名称计算哈希:该哈希是 [source, methods] 经 JSON 编码后的 SHA-256 摘要。host 只处理这些名称的调用,因此运行只能调用哈希所涵盖的方法。每次运行都携带该哈希,并且只在该连接的守护进程应答过一次携带定义的运行之前携带该定义,即其源码和方法名称;源码和处理函数名称都相同且名称顺序一致的定义共用同一缓存条目,而源码相同时,处理函数名称不同或者名称相同但顺序不同的,则是另一个定义。守护进程按哈希校验每个收到的定义,并在该连接内保留它;每个 worker 对一个定义的源码只编译一次,但仍在每次运行时于全新的上下文中求值,因此缓存不改变任何调用方。缓存只在其连接存续期间有效,因为每个连接都会启动全新的守护进程。守护进程以结果或错误应答过一次携带某个定义的运行后,注册表就省略这个定义:守护进程在运行函数之前就会保留校验过的定义,因此只有缺陷才会让守护进程不认识已应答过的定义,而守护进程会拒绝指明未知哈希的运行;不存在重试交换。

每次运行占用一个 worker 线程

一个 host 连接承载使用某个环境的所有 Session 的运行。阻塞其线程的函数(例如大量回溯的正则表达式或 CPU 循环)原本会使该连接上的所有运行停滞,host 随后会关闭该连接,其他运行及其 exec 进程也随之结束。因此,守护进程为每个连接维护一个 worker 线程池:一次运行占用一个 worker,并在运行结束时归还,线程池因而增长到该连接的峰值并发数,该并发数受 maxPending 限制;关闭连接会结束所有 worker。取消会中止函数的 env.signal;如果函数在 cancelGraceMs 的一半时间内仍未停止,守护进程会终止其 worker,并在 host 的截止时间之前应答该取消,因此连接及其上的其他运行可以继续。exec、其进程组清理和发起端调用留在主线程上,主线程拥有该连接启动的所有进程。守护进程以单个文件安装,因此每个 worker 都从一个自包含函数的源代码文本启动。

值以 postMessage 结构化克隆的形式在主线程与 worker 之间传递。该算法接受的值与连接的帧接受的值相同,但会把 Buffer 复制为 Uint8Array,因此参数、结果或发起端值中的 Buffer 到达时是 Uint8Array。错误以其名称、消息和字符串错误码跨越线程边界和连接,因为结构化克隆只保留标准错误名称,并丢弃 code。

没有任何代码捕获的异常(例如在定时器回调中抛出的异常)会使其 worker 正在执行的运行失败,而不会结束该 worker,也就不会连带结束一个可能并非其起因的运行。在两次运行之间,worker 会把这类异常报告到标准错误,并继续服务。运行的定时器(包括 AbortSignal.timeout 的定时器)随运行一同结束,其中止监听器在运行结束时执行,因此在后续运行期间仍可能执行的,只有已结束运行自身未完成操作的后续回调;这些回调留下未捕获的异常时,会使该后续运行失败。

传输是插件

守护进程只需要一个字节流。提供方通过 ctx.environments.register(info, transport) 注册环境元数据和传输实现;每次 open 返回一个带有安全属性和结束原因的通道。随附的 SSH 传输通过 OpenSSH 直接运行 daemon.js serve --stdio;本地传输在受管理的 Node 进程中启动同一入口。每个新连接启动全新的守护进程,注册表则复用活跃通道,并且不会重放已发送的运行。传输实现负责进程的启动和停止;注册表负责协议和连接缓存。一个提供方可以注册多个环境,每次运行指定一个提供方贡献的句柄。

信任来自传输,握手为更多机制保留位置

任何能连接的人都能以守护进程用户的身份运行代码,因此通道访问权限决定谁能执行。每个连接以 auth 开始,它协商一种机制并设定该连接的限制。唯一的机制是 transport:SSH 认证用户和主机,严格检查主机密钥,未知密钥通过 ssh 获取以使代理设置生效,且只有在指纹已固定或经人确认后才被信任。本地提供方管理其子进程和管道。最初基于 socket 权限的信任模型已由传输进程管理取代。不存在网络监听器。网络传输必须先认证通道,并将认证与该通道绑定,才能接受执行请求。

请求双向传输,支持取消,并且每个方向各有 maxPending 名额。已取消的请求会一直占用其名额,直到另一个对端应答它,因此两个对端统计的工作量相同;未在 cancelGraceMs 内应答取消的对端会失去连接,下一次运行会重新连接。

值以结构化克隆的形式在拆分的帧中传递

每个帧由 4 字节长度和其后的 node:v8 序列化数据组成,因此参数、结果和发起端值都是结构化克隆。两个对端都运行受支持的 Node 版本,因此工具可以用 Uint8Array 传递文件字节而无需 base64,可以保留 undefined、Date、Map 和 bigint,并可以用接口为参数声明类型;同时 zod 仍会校验每个解码后的帧。大于 maxFrameBytes 的消息以 part 帧传输,接收方在协商的 maxMessageBytes 以内将其重组。不同消息的分段相互交错,因此取消请求或小型发起端调用最多只需等待大型传输的一个帧,被取消的传输会停止发送其剩余分段。错误帧携带所抛出错误的名称、消息和字符串错误码,因此 errno 或 HarnessError 错误码在两个方向上都能经过连接保留下来。

调用方只看到消息上限。注册表以 ctx.environments.limits 公开该上限,因为它是注册表范围内的单一值,每个连接都以相同的值协商;函数以 env.limits 读取同一个值。

对端同时分段发送的消息,大小之和不超过 maxMessageBytes;更多的消息按顺序等待,而单帧即可容纳的消息从不因额度而等待。接收方执行同样的总量上限,并要求除消息最后一段外的每一段至少携带一个最小尺寸帧所能容纳的数据,因此在每个方向上,重组最多保存 maxMessageBytes 字节,且分段数量有界。在等待中被取消的请求尚未发送任何内容,会立即释放其名额。接收方不再计入它已取消的请求的应答,因此发送方可以在已停止应答的错误帧到达之前,就收回该应答占用的额度。

共享的对端代码

请求对端的取消记账逻辑与 SSH helper 的对端相同,并带有一个 jscpd:ignore 例外。SSH 对端在长度前缀的帧中使用 JSON 载荷,并使用 UUID id、按请求类别划分的管理限制以及 SSH 专用诊断信息,而且不拆分消息,因此共享这段代码会把 SSH 行为移入通用包,或把 SSH 措辞移入本包。当第三个消费方需要相同的请求语义时,再提取一个对端包。

考虑过的替代方案

  • 只使用远程 ctx.fs 和 ctx.subprocess。 对于工具 I/O 予以否决:每个原语都是一次往返,工具无法把多步操作保留在远程机器上。
  • 在远程机器上运行 Harness 运行时的一个子集。 否决:插件需要安装在 host、远程机器或两者之上,远程运行时也需要随插件一起更新。
  • 带有自身插件接口的原生守护进程,每次插件变更时重启。 否决:它需要第二套插件系统,而且重启会中断所有远程运行。
  • 与单个 SSH 会话的标准输入和标准输出绑定的守护进程。 最初否决的原因是它会随断连退出,而且每种传输都需要启动路径。该否决已由传输进程管理取代,启动和持久运行机制归传输实现负责。
  • 复用 dsh-ssh helper 作为传输。 最初否决的原因是其按连接或租约进行的清理与常驻进程决策冲突。传输进程管理取代了该常驻要求;基于 ctx.ssh.connectStream 的提供方仍是独立的传输选择。
  • 拒绝第二个 host 连接。 最初否决的原因是残留或阻塞的连接可能妨碍重连。传输进程管理中的每连接独立进程模型取代了共享监听器的连接接纳决策。
  • 按调用传入处理函数。 处理函数可以通过闭包捕获每次调用的 host 对象。作者予以否决:调用方若有按调用区分的 host 状态,则为每次调用分别定义。同一否决最初也涵盖按调用传入句柄;运行器选择句柄取代了这一部分。
  • 在守护进程主线程上对函数求值。 否决:node:vm 的 timeout 选项只限制同步求值,而被阻塞的主线程会使协议以及该连接上的其他所有运行停止。
  • 每次运行使用新的 worker 或子进程。 否决:每次运行都要承担线程或进程的启动开销,子进程还会增加一棵需要监管的进程树。线程池复用 worker,同时每次运行仍获得全新的上下文。
  • 比所属连接存活更久的定义缓存。 否决:每个连接都会启动全新的守护进程,因此存活更久的缓存需要守护进程侧的存储和失效机制。
  • 在每次运行中携带发起端方法名称。 否决:define 固定了处理函数名称,因此这些名称属于连接所缓存的定义;在每次运行中重复携带这些名称只会增加字节,不会增加信息。
  • 以换行分隔的 JSON,并用 base64 传输字节。 否决:base64 会使二进制载荷增大三分之一,JSON 会丢失 undefined、日期和 Map,JSON 类型不接受接口,而且工具需要针对自己看不到的帧上限自行实现编解码和分片。
  • 在 list() 或 EnvironmentInfo 中提供消息上限。 否决:该上限是注册表配置,对所有环境都相同,而 EnvironmentInfo 保存的是提供方贡献的元数据。
  • 只用待处理名额限制仅部分接收的消息。 否决:按默认值,maxPending 个请求加上同样数量的应答、每条 maxMessageBytes,每个方向合计可达 8 GiB;而如果接收方的上限低于发送方可以发送的量,就会关闭遵守协议的连接。
  • 在已认证通道上使用应用层密钥。 推迟:通道访问权限本已允许以守护进程用户身份执行。最初的 Unix socket 论据还依赖文件系统权限;传输进程管理移除了该已部署机制,同时保留通道认证和可扩展的 auth 交换。

影响

  • 工具只保留一个 Harness 运行时和一份插件安装;远程代码是每次运行时发送的普通 JavaScript。
  • host 的转译器运行后,发送的源码必须仍然自包含。守护进程为 esbuild keepNames 输出定义了空操作的 __name;其他转译器或插桩辅助函数会在运行时失败。
  • 运行上下文提供的实用 API、运行的参数以及其 env 返回的值都来自其 worker 的 realm,因此用上下文自身的内置对象(如 Uint8Array)对这些对象执行 instanceof 检查时,结果可能为 false。
  • node:vm 在运行之间隔离全局对象,但不是安全边界:远程代码以守护进程用户的权限运行,并绕过 ctx.sandbox。
  • EnvironmentValue 接受接口,因此在编译期也会接受函数;结构化克隆会在编码这类值所在的消息时拒绝它们,此时尚未发送任何内容。
  • 两个对端必须能读取彼此的 node:v8 格式版本;Node 24 和 26 共用版本 15。
  • 目前还没有已发布的工具使用本服务;Bash、文件工具和 PTC 仍使用已挂载的 ctx.fs 和 ctx.subprocess 提供方。