Embeds as a library
A pure JavaScript package for Node ≥ 24 or Bun ≥ 1.4, with no WASM module, native addon, or isolate to wire up. Call Runtime.make, pass plain host functions, and run.
原始链接: https://psychoscript.com/
NormalScript® 是一个面向 Node ≥24 或 Bun ≥1.4 的小型、快速嵌入式 JavaScript 虚拟机。它在现有进程内以脚本或代理代码模式运行 JavaScript 的严格子集,不使用 WASM、原生插件或 worker。开发者使用 `Runtime.make` 创建运行时,通过 `Host.fn` 和命名空间暴露普通宿主函数,然后调用 `runtime.execute` 或 `program.run`。脚本可以链式调用宿主函数,并使用 async 函数、生成器、类以及顶层 await/return。运行可被挂起,使用 `toBytes()` 序列化,并在之后使用 `fromBytes()` 和 `runtime.resume()` 恢复,在全局变量和构建匹配时保留状态。虚拟机支持 JSON 类似的结果传递、限制、取消、持久调用和流式处理。它在范围内通过了 19,408 个中的 22,253 个 test262 文件。它采用 MIT 许可证,省略了定时器、I/O、磁盘模块加载、动态代码、非严格模式以及许多高级元编程功能。
Enterprise scripting solutions
NormalScript® is a small, fast virtual machine for a subset of JavaScript. It embeds in your Node or Bun application: give it a few host functions and it runs little scripts and agent code mode, pausing to bytes and resuming later. Nothing unusual happens here.
Review capabilities View compliance matrix View on GitHub
Trusted by more than 400 normal organizations · Node ≥ 24 or Bun ≥ 1.4 · MIT licensed
0
WASM modules, native addons, or workers to wire up
1
Call to run a script: runtime.execute(code)
19,408
test262 files passing; 2,845 skipped as known gaps, 0 failing
Bytes
What a paused run is saved as, and resumed from
Core capabilities
For teams that run little scripts, plugins, lightweight workflows, or agent code mode inside a Node or Bun application, without operating a second runtime.
A pure JavaScript package for Node ≥ 24 or Bun ≥ 1.4, with no WASM module, native addon, or isolate to wire up. Call Runtime.make, pass plain host functions, and run.
Scripts compile to bytecode and run on a compact virtual machine inside your process. There is no worker to spawn and nothing to boot, so a run starts when you call it and stops on timeoutMs or an AbortSignal.
An agent, user, or plugin writes one script that chains many host calls, with loops, branches, and Promise.all in between. Errors return a kind, a message, and optional suggestions.
Host.fn turns an ordinary function into a global. Host.namespace resolves large catalogs lazily. Host.durableFn keeps long work running across a suspend. StreamingResponse streams a response body.
Suspend a waiting run with program.suspend(), save its state with toBytes(), and continue it with fromBytes() and runtime.resume(). Same build, same globals, same result.
Scripts are written in a modern, strict-mode subset of JavaScript: async functions, generators, classes, and top-level await and return. The host API is Promise-based, with the same names over Effect at /effect.
Reference integration
Runtime.make takes a globals function and optional limits. Plain objects of host functions act as namespaces. Arguments reach the host as copies, and results are copied back. There is no further setup.
Exhibit A · A code-mode script chaining host calls
import { Host, Runtime } from "normalscript"
const ledger = [
{ id: "INV-1", total: 1200, paid: true },
{ id: "INV-2", total: 450, paid: false },
{ id: "INV-3", total: 80, paid: false },
]
const outbox = []
const runtime = Runtime.make({
limits: { timeoutMs: 1_000 },
globals: () => ({
invoices: {
list: Host.fn(() => ledger),
remind: Host.fn(([id]) => outbox.push(id), {
type: "async",
}),
},
}),
})
// Code mode: one script, several host calls.
const result = await runtime.execute(`
const due = invoices.list().filter((i) => !i.paid)
await Promise.all(due.map((i) => invoices.remind(i.id)))
const owed = due.reduce((sum, i) => sum + i.total, 0)
return { reminded: due.length, owed }
`)
console.log(result.value)
// { reminded: 2, owed: 530 }
Exhibit B · Suspend, save, and resume
import {
Host,
Runtime,
fromBytes,
toBytes,
} from "normalscript"
const slow = ([n]) =>
new Promise((done) => setTimeout(() => done(n * 10), 50))
const runtime = Runtime.make({
globals: () => ({
fetchMetric: Host.fn(slow, {
type: "async",
idempotent: true,
}),
}),
})
const program = runtime.program(`
let total = 0
for (const n of [1, 2, 3]) total += await fetchMetric(n)
return total
`)
const running = program.run()
// Pause the run mid-call and save its state as bytes.
const outcome = await program.suspend()
await running
const bytes = toBytes(outcome.state)
// Later, in any process with the same build and globals.
const result = await runtime.resume(fromBytes(bytes)).run()
console.log(result.value)
// 60
Operational specifications
How a run starts, stops, pauses, and resumes. All behavior below is standard.
Embedding
Runtime.make({ globals, limits }) returns a runtime. globals is called for each run, and again on resume, with the run's id and metadata. Globals shadow built-ins of the same name.
Host calls
A sync host function returns its value to the script directly. An async one gives the script a promise at once. Host calls may run concurrently. Host.fail gives the script a catchable error with your own kind.
Results
{ ok: true, value } or { ok: false, error: { kind, message, suggestions? } }, plus console logs, warnings, and the run's metadata. The value crosses as JSON.stringify would serialize it.
Limits
Two options, neither set by default. timeoutMs is active time, summed across resumes and checked between VM steps; a single regular-expression match runs on the host engine and is not interrupted. maxOutputBytes is the UTF-8 bytes kept from the result and logs, with an equal budget for warnings; the rest is cut. There is no separate memory or step-count limit.
Fixed caps
Strings: 2^24 characters. Arrays: 10,000,000 elements. Pending promises: 10,000. Nesting across the host boundary: 32 levels. Exceeding a cap throws a RangeError in the script.
Cancellation
Aborting the signal passed to execute() or program.run() aborts every host call's call.signal and rejects the run with an AbortError. A host call that ignores its signal is not waited for.
Snapshots
suspend() returns the run's state; toBytes() and fromBytes() turn it into bytes and back. A snapshot resumes on the build that wrote it. Another build, or malformed bytes, rejects with a SnapshotError. suspend({ maxBytes }) caps the size. Store snapshots as you would store code.
Host calls during suspend
An async call marked idempotent runs again on resume with the same call.key. Otherwise suspend() rejects with a SuspendError while the call is in progress, and the run goes on.
Durable calls
Host.durableFn work keeps running across a suspend. start() returns JSON kept in the snapshot, wait() gets the result, again after a resume, and cancel() runs if the run ends without it.
Determinism
Runs are deterministic except for Math.random(), Date.now(), new Date() with no arguments, crypto.randomUUID(), and crypto.getRandomValues(). There is no option to seed them. A host may shadow them with globals; the replacement is the whole object.
Effect API
Optional. The /effect entry point exports the same names with an Effect API. Host functions may return Effects, and interrupting a run interrupts its host calls. The Promise API has no dependency on Effect.
Scope and compliance matrix
NormalScript® is a small embeddable virtual machine for a subset of JavaScript, not a full runtime such as Node, Bun, or a browser. Whatever a script needs from outside, the host passes in. The omissions below keep it small.
Evaluation and procurement
NormalScript® is distributed under the MIT License. To begin an evaluation, request a demo or download the white paper. Both are standard next steps.
Form NS-7 · Declaration of Normal Viewing
I, the undersigned, declare that I viewed the NormalScript® website and that nothing unusual happened.
I did not take the tab. I did not see a sun, a face, a valley, a terminal, a planet, a snake, or my manager. Any colours I recall were within brand guidelines.
I understand that this declaration may be audited.
SignatureDate
Retain for your records. Do not fold.