You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
computer, docs: document the process shim and cover the stdin ceiling
Add a section to the JavaScript runtime doc describing the process shim:
caller-supplied env exposed through process.env with the host
environment hidden, caller-supplied stdin as a non-interactive
async-iterable bounded by maxStdinBytes, stdout and stderr capture with
console routing, and inert argv, cwd, and platform. List maxStdinBytes
among the configurable byte limits.
Add a test asserting an oversized stdin fails the run before the loader
is invoked.
Copy file name to clipboardExpand all lines: docs/17_isolate_javascript.md
+30-1Lines changed: 30 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -91,6 +91,35 @@ Cancellation stops new host capability calls, disposes the Dynamic Worker, and w
91
91
92
92
Host calls have a caller-visible deadline, controlled by `maxHostCallMs` and defaulting to `maxTimeoutMs`. Missing the deadline fails the capability call and marks the execution failed, even if caller code catches that error. Execution still waits for the accepted host operation itself before publishing a terminal event because many host APIs cannot roll back an external side effect after dispatch. Trusted modules receive an optional `{ signal, deadline }` context and must stop promptly when the signal aborts. A trusted module that ignores cancellation and never settles will keep execution in its finalizing state. `compatibilityDate` and `compatibilityFlags` control the Dynamic Worker runtime and default to the package-tested settings.
93
93
94
+
## Environment, standard input, and the `process` shim
95
+
96
+
Each execution installs a small `node:process` shim so ordinary module code can read its environment and standard streams. The shim exposes only what the caller supplies for that execution; the host environment is never visible.
97
+
98
+
`process.env` is a snapshot of the `env` record passed on the exec options. Values the caller does not pass are absent, and the Durable Object's own environment is never merged in, so a module cannot read host bindings or secrets through `process.env`.
99
+
100
+
`process.stdin` is a non-interactive async-iterable over the caller-supplied `stdin` bytes. The caller passes `stdin` as a `Uint8Array` or string on the exec options; `for await` yields the bytes once and then ends, and there is no blocking read for further input because an evaluate-once execution has no session to wait on. `isTTY` is `false`. The supplied input is bounded by `maxStdinBytes`; exceeding it fails the run with a clear error.
101
+
102
+
`process.stdout` and `process.stderr` are writable streams whose writes are captured as standard output and standard error. `console.log` and `console.info` route to standard output, `console.warn` and `console.error` route to standard error, and the captured output is bounded. `process.argv`, `process.cwd()`, and `process.platform` return inert values: `cwd()` reflects the execution's working directory, while `argv` and `platform` carry fixed placeholders rather than describing the host process.
103
+
104
+
```ts
105
+
const handle =awaitworkspace.runtime.exec(
106
+
`
107
+
export default async function main() {
108
+
let piped = "";
109
+
for await (const chunk of process.stdin) piped += new TextDecoder().decode(chunk);
110
+
console.log("received", piped.length, "bytes");
111
+
return { who: process.env.WHO, piped };
112
+
}
113
+
`,
114
+
{
115
+
backend: "worker-javascript",
116
+
env: { WHO: "demo" },
117
+
stdin: "hello",
118
+
encoding: "utf8",
119
+
},
120
+
);
121
+
```
122
+
94
123
## Configured modules
95
124
96
125
Bare imports are installed at backend construction, not passed on individual executions:
@@ -156,7 +185,7 @@ Each execution receives a fresh Dynamic Worker with:
156
185
- a host wall-clock deadline;
157
186
-`globalOutbound: null` by default;
158
187
- finite, acyclic JSON-compatible input and structured result validation;
159
-
- configurable source/module graph, input, result, captured-log, file/capability request, and response byte limits (`maxSourceBytes`, `maxInputBytes`, `maxResultBytes`, `maxLogBytes`, and `maxCapabilityBytes`);
0 commit comments