Psychoscript: Agent Code You Can Pause and Resume

Agents write code now. Lots of it. The awkward part is running it. Psychoscript, a resumable JavaScript interpreter that Anomaly (the company behind OpenCode) pulled out of OpenCode's Code Mode and shipped on its own, takes a blunt view of the problem: give the script nothing, and let it pause whenever it likes.
OpenCode announced it on X on 25 November (UTC): "we extracted the runtime powering codemode into a standalone project." The package is MIT licensed, needs Node 24+ or Bun 1.4+, and uses no WebAssembly.
What Psychoscript actually is
Psychoscript compiles a strict-mode subset of JavaScript to bytecode and runs it on its own small virtual machine. The script starts with no ambient access. No fetch, no file system, no process, no timers, no eval, no Proxy. The only way it can touch the outside world is through host functions you pass in. Arguments and results get copied across that line, not shared.
That is a language-level sandbox. The script can't read your disk because the language has no word for "disk".
The second trick is the one in the name of this post. A run can be suspended while it waits on something, saved as bytes, and resumed later. Same process or a different one. Same result.
A quick example
Say your agent writes a script that loops over three invoices, asks a human to approve each one, then sums the totals. Approval two takes until Monday. A normal process would sit there holding memory, or crash at the next deploy and lose its place.
With Psychoscript, the host calls program.suspend(), turns the state into bytes with toBytes, and stores it wherever it likes. On Monday, runtime.resume(fromBytes(bytes)).run() picks up at the loop where it stopped. The README's own toy example saves a snapshot of 5,402 bytes. Picture that as a database row instead of a server kept awake all weekend.
The catches are in the README, which I respect
The project is honest about its limits, and they matter:
- Snapshots are build-locked. Each snapshot records the build that wrote it. Upgrade the package between pause and resume and you get a
SnapshotError. - Host calls can run twice. A call in flight during a suspend is re-run on resume, which is why it must be marked
idempotent. Charging a card twice is not a fun way to learn this. - Limits are off by default.
timeoutMsandmaxOutputBytesdefault to none, and there is no separate memory limit. - Regex can hang. One regular-expression match runs on the host engine and can't be interrupted.
- Treat snapshots like code. The README says it plainly: whoever can edit one controls the resumed run.
My take: this is a good layer, not the only layer. For scripts your own agent writes against your own tools, language confinement plus timeouts is sensible. For code from strangers, I would still put a process or VM boundary around it. Defence in layers is boring, and boring is the goal.
Why agent builders care
Code Mode is the idea that an agent should write one script that chains many tool calls, instead of calling tools one at a time and dragging every result back through its context window. Cloudflare introduced the idea. The hard part was always where that script runs. Psychoscript answers with "somewhere that can't do anything you didn't hand it, and can wait as long as it needs to."
It's also young. The first npm release landed on 17 November, version 0.4.0 shipped on 27 November, and 0.2.0 was already a breaking change. Pin your version.
Here is the surprising bit: the project's website poses as "NormalScript®", a deadpan parody of enterprise software, while npm counted 54,810 downloads in the week of 21 to 27 November. So, would you let an agent's half-finished script sleep in your database over the weekend?