Edge.js: Run Node apps inside a WebAssembly sandbox (wasmer.io)

by syrusakbary 45 comments 173 points
Read article View on HN

45 comments

[−] syrusakbary 60d ago
Hi HN!

I'm Syrus, from Wasmer. We built Edge.js in a few weeks after different trials trying to bring Node.js to the Edge. We used AI and Codex heavily for this project, as otherwise the timeline would have spanned to a year plus to develop.

The summary of this announcement is that Edge.js:

  * Runs using WebAssembly when in `--safe` mode
  * It's fully compatible with Node.js (passing all their spec tests for non-VM modules)
  * It has a pluggable JS engine architecture: can work with V8, Javascript, SpiderMonkey, QuickJS, Hermes, etc.
Super happy to answer any questions you may have!
[−] jonny_eh 60d ago

> * Runs using WebAssembly when in

--safe mode

Why is safe mode opt-in?

[−] gamebak 60d ago
noob question, but how can you create a localhost:3000 port, when ported to wasm, in the browser?

I think this is a cool demo for you to show, at least in my mind this might be a little mind blowing + maybe a db?

I know there are wasm dbs availble that are very light, but so that maybe it's a plus to consider.

[−] gavinray 59d ago
Node does not run in a browser?
[−] syrusakbary 59d ago
Yet... stay tuned!
[−] bhelx 60d ago
Just wanted to chime in to say this is really cool. I dreamed of building something like this for the Extism ecosystem but it was a huge lift to unlock all the pieces. This looks like lots of innovation all the way down the stack. Kudos!
[−] syrusakbary 59d ago
Thanks Ben! Took us a bit to figure out the best architecture for it, but once it became clear then it was just a matter of implementing the missing bits.

I think the fact that WASIX is much more mature now have helped to increase development speeds quite a bit!

[−] larsnystrom 60d ago
Maybe I’m just dense, but it says the fs module is fully supported, so what happens when I try to read a file from disk if the app is fully sandboxed?
[−] Onavo 60d ago
What's the Next.js compatibility like?
[−] willquack 60d ago
Awesome project!

Dumb question: could you run this in frontend js using the browser's js engine and wasm environment similar to WebContainers? Maybe fs is just in-memory, and some things like forking are disabled. It'd be cool to have "nodejs" in the web!

[−] pacman1337 60d ago
Not sure I understand the use cases. I'm guessing people want to run unsafe nodejs code. Either cloud providers like for lambdas or on personal computer for AI coding? On cloud why is this better than firecracker, firecrack can run any programming language this is just nodejs so already useless for that use case?

For personal computer, people worried about the spin up time of docker? I think that is more of a tooling issue where you spin up one instance and run multiple jobs.

What am I missing? What are actually real use cases where this would be better?

[−] d0100 60d ago
I still prefer Deno because I don't need a separate npm install command, which makes running code that much easier

Being able to import from "https://my-vpn.com/mypackage@1.2.3" or "npm:package@1.2.3" and just running code without having to worry about scaffolding node_modules makes sandboxing code much easier

[−] ammmir 60d ago
I don't get it. You mention being able to choose your own JS engine, so it's not using Wasmer's WebAssembly implementation but that of the chosen JS engine's? In other words, can Edge.js use Wasmer? Or have you managed to compile V8/JSC into WebAssembly and are executing it with Wasmer? If so, amazing!
[−] pscanf 60d ago
Very cool project!

Question regarding the pluggable js engine: I have an electron app where I'm currently using QuickJS to run LLM-generated code. Would edge.js be able (theoretically) to use electron's v8 to get a "sanboxed within electron" execution environment?

[−] MillionOClock 60d ago
Very interesting! On what platforms can this run? If it can run on iOS, how would you handle attempts to access to the file system or networking, is this already wired in somehow? If not is it easy to add custom handlers to handle these actions?
[−] alex_reg 60d ago
It's a bit confusing.

Roughly:

* a refactor of Node.js, but using a standardized API for JS engine interop * Integration with the Wasmer CLI so it will run JS with v8 but, everything else in Webassembly

Interesting idea.

Could be a much lighter weight way to sandbox JS...

[−] huksley 59d ago
How to run it embeddable, i.e. can I load unsafe code in existing typescript codebase using it?

What is the lifecycle of the sandbox? Can we pause, step-by-step, pause and resume executed code?

[−] drewbitt 59d ago
Sick! Love me some Wasm solutions like this
[−] 2001zhaozhao 60d ago
Huh. Could this be a way to sandbox user-generated JS in web apps?
[−] actionfromafar 60d ago
Can that Node app load and run WebAssembly?

(A.K.A. are we IBM 360 yet?)

[−] robjam 60d ago
Wow! Node APIs in wasm(wasix)? Something that I have been thinking over for a long time is getting wasm (just wasm, not wasi or com) to be the unit of deployment/packaging for web apps like Nuxt/Next that only depend on, for example SQLite or Postgres. Slightly ignorant question, but would edge.js allow integrating with a caddy plug-in to handle serving the app from wasm?

I know of the extism project and played around with it in elixir, but I'm looking to have CF Workers DX with as little operational complexity as possible for many silly pet projects.

[−] davispeck 60d ago
[flagged]
[−] leontloveless 60d ago
[dead]
[−] iam_circuit 60d ago
[dead]
[−] aplomb1026 60d ago
[dead]
[−] eu_93 56d ago
[dead]
[−] Heer_J 59d ago
[dead]
[−] billionverify 59d ago
[flagged]