DEV Community

Dishant Sharma
Dishant Sharma

Posted on Edited on Originally published at dishantsharma.dev

Psychoscript: The Sandbox That Can Pause Mid-Script

"Trusted by more than 400 normal organizations."

That line sits on psychoscript.com, under a serif headline reading "Enterprise scripting solutions." The nav has Compliance and Procurement. The docs have an Exhibit A and an Exhibit B.

The product is a JavaScript interpreter. The site is a straight-faced parody of every enterprise SaaS page you have scrolled past this year. And it works, because the thing underneath is real.

psychoscript is the runtime that powered OpenCode's code mode, pulled out into a standalone package. The repo went up on November 13. It is MIT, at v0.3.0 on npm, sitting at 315 stars. The joke does not stop at the homepage.

One detail made me laugh. On Hacker News, where the site was posted as "NormalScript: A perfectly normal scripting language," it pulled 21 points and almost no discussion. The comments are three people reacting to the demo animation.

"Impressive and mind-melting. Eventually crashed my browser but it was worth it."

A demo so heavy it killed a tab. That is a better product story than most launch posts manage.

What it really is

The README opens with one sentence that explains everything. "A confined, resumable JavaScript interpreter."

Programs compile to bytecode. The bytecode runs on a small VM written for this purpose. That VM has no file system, no network, no process, and no timers. The only door out is a host function you hand it.

import { Host, Runtime } from "psychoscript"

const runtime = Runtime.make({
  globals: () => ({ double: Host.fn(([n]) => Number(n) * 2) }),
})

await runtime.execute("return [await double(21), [1,2,3].map(x => x + 1)]")
// {"ok":true,"value":[42,[2,3,4]],"metadata":null}
Enter fullscreen mode Exit fullscreen mode

That is the whole surface. No worker to spawn. No isolate. No WASM module to load.

The absence of WASM is the actual headline, and the announcement buried it.

Most sandboxing stories end with "and then we boot a WebAssembly runtime." psychoscript skips that. It is a plain package for Node 24+ or Bun 1.4+. You install it and call a function.

The security model is the interesting part, not the API. No eval. No Function constructor. No Proxy or Reflect.

Also no Object.setPrototypeOf and no __proto__ assignment. Strict mode only, always. That list is deliberate. Every one of those is a way to escape a sandbox from the inside.

The pause button is the strange part

Here is where it stops being a normal sandbox.

A run can be suspended mid-execution, turned into bytes, and resumed somewhere else. Same build, same globals, same result.

const toBytes   = (state) => state   // from psychoscript
const program = runtime.program(code)
const running = program.run()
const outcome = await program.suspend()
const saved = toBytes(outcome.state)  // ~5402 bytes
Enter fullscreen mode Exit fullscreen mode

Later, in another process, runtime.resume(fromBytes(saved)).run() picks up exactly where it stopped.

Think about what that means for a script waiting on a webhook. Or a workflow waiting three days for a human to approve something. The program does not sit in memory. It sits in a row in your database.

There is a catch, and it is a sharp one. If the program is waiting on a host call when you suspend, that call has to be marked idempotent. On resume it runs again with the same call.key.

Without that flag, suspend() rejects with a SuspendError and the run just keeps going.

And the snapshot records the build that wrote it, down to a hash of the opcodes and the prelude. Load it against a different version and you get a SnapshotError.

A snapshot is executable state. Store one like you store code, because anyone who can edit it controls the resumed run.

Why an agent wants this

Code mode is the reason this exists. An agent writes one script that makes many tool calls, and only what the script returns goes back into context.

const files = await tools.search("retryPolicy")
const edits = await Promise.all(files.map(f => tools.edit(f, "maxAttempts: 3", "maxAttempts: 5")))
return edits.filter(e => !e.ok)
Enter fullscreen mode Exit fullscreen mode

Three paragraphs of tool output become one line of real results. That is the token argument, and it is the one everyone makes.

But there is a second argument that gets less attention. Armin Ronacher made it when Pi shipped codemode over MCP. Code mode runs on the agent host, not inside the sandbox.

It is a way for the model to orchestrate the brain side without touching the hands.

That distinction matters for trust. The script that coordinates has no file system and no network. The tools that do are explicit, named, and you wrote them.

There is also state. A codemode invocation can stash data that the next call loads back. On the host, not in the sandbox.

For a long agent session, that is a working memory that survives compaction.

What developers get out of it

The pitch on the site is aimed at teams embedding scripting in an existing app. Plugins. User-defined workflows. Little rules that run inside your product.

Before this, you had three choices, and all of them hurt:

  • spin up a separate service to run untrusted code
  • pull in a WASM JS engine and accept the boot cost
  • use node:vm and pretend it is a sandbox (it is not)

psychoscript is the fourth option. It embeds as a library, runs in your process, and starts when you call it.

And the Rust side is further along than "in the works" suggests. The crate is already in the repo, with its own README and its own benchmark table against the TypeScript build: 34x faster to start, 4.3x faster per program on a 429-program corpus.

The Rust version also gets things the JS one does not. A heap cap. CPU-time budgets. A slice limit for the longest stretch between host awaits.

For native apps, the typed array story is the part that matters. A synchronous host function can borrow the program's own bytes with no copy at all. Read them in place and push them straight to a GPU.


Small tangent. The name situation is a mess and i mean that fondly.

The repo is psychoscript. The website sells NormalScript®. The npm package is psychoscript. The announcement called it "physcoscript," which is a spelling that exists nowhere in the actual project and will haunt every search result for a year.

Somebody clearly realized "psychoscript" sounds like a serial killer's hobby language and built an entire enterprise parody around the correction. The joke is genuinely well executed. The Compliance page alone is worth a click.

The real talk

Do not reach for this if your scripts are one-shot.

Suspend and resume is the hard part of the project, and if you never resume, you are paying for complexity you do not use. A plain node:vm call or a child process is fine for a five-second script.

Also, it is not a full JavaScript runtime, and the gaps are real. No setTimeout, no event loop, no fetch, no fs, no AbortController.

Un-awaited promises get killed when the program returns.

And you cannot pass a guest function into a host function yet. Host arguments are copied. So anything callback-shaped is off the table for now.

One more, from the security section, and Cloudflare's round found the same hole: a single regex match runs on the host engine and cannot be interrupted. A pathological pattern can run long. timeoutMs will not save you from a bad regex.

Then there is the small matter of the numbers disagreeing. The README says 19,802 test262 files pass with 2,667 skipped. The website says 19,408 passing with 2,845 skipped.

Both say zero failures, so the shape of the claim holds. But the site's compliance matrix is slightly stale.

For a project whose entire joke is enterprise compliance, that is a funny place to drift.

One last thing

The thing i keep thinking about is not the sandbox. It is that a script can survive a restart.

Every workflow engine i have used ends up reinventing this. You write a state machine, you persist steps, you reconcile on boot. Someone always gets it wrong around retries.

Having it at the language level, in a package you npm install, is a different kind of idea. The language itself remembers where it was.

And yes, the site crashed a browser. I still clicked the smile.

Top comments (0)