Hacker News 中文摘要

RSS订阅

Edge.js:在WebAssembly沙箱中运行Node应用 -- Edge.js: Run Node apps inside a WebAssembly sandbox

文章摘要

Edge.js是一个基于WebAssembly的JavaScript运行时,可在沙箱中安全运行Node.js应用,保持完全兼容性的同时通过WASIX隔离系统调用和原生模块,适用于AI和边缘计算场景,无需Docker即可实现高效安全的执行环境。

文章总结

Edge.js:在WebAssembly沙箱中安全运行Node.js应用

Wasmer团队近日开源了Edge.js,这是一个专为AI和边缘计算设计的JavaScript运行时,能够在WebAssembly沙箱中安全运行Node.js工作负载。

核心优势: 1. 完全兼容Node.js(v24版本),现有应用无需修改即可运行 2. 采用创新架构将执行环境分为两个隔离层: - 通过napi接口暴露的JS引擎(支持V8/JSCore/QuickJS) - 通过WASIX沙箱化的系统调用和原生代码 3. 在--safe模式下提供安全沙箱,性能仅比原生Node.js慢5-30%

技术突破: - 相比Deno/Cloudflare Workers等方案,Edge.js保持了完整的Node.js生态兼容性 - 不同于将整个V8编译为WASM的方案(如Node-WASIX),Edge.js仅沙箱化不安全部分 - 采用与Node相同的底层依赖(libuv/llhttp/ncrypto等),确保行为一致性

性能表现: 当前版本已通过3626项Node核心模块测试中的3592项(99%通过率),远超Bun和Deno的兼容性。虽然启动时间暂劣于Node,但团队已制定优化路线图,计划通过JS字节码快照等技术提升性能。

诞生背景: Wasmer团队发现现有方案存在局限: - WinterCG标准导致生态碎片化 - 容器方案无法满足边缘计算对启动速度和部署密度的要求 - 完全WASM化的Node方案性能损失严重

开发者可通过以下命令快速体验: bash curl -fsSL https://edgejs.org/install | bash edge myscript.js

该项目得益于GPT-5.4的辅助开发,使小型团队在数周内完成了原本需要1-2年的工程。团队承诺对兼容性问题提供一周内快速修复的保障。

(注:原文中大量技术细节对比、性能数据表格及开发历程描述已精简,保留核心技术价值和差异化优势信息)

评论总结

以下是评论内容的总结:

  1. 项目介绍与功能

    • 作者Syrus介绍了Edge.js,一个通过AI辅助快速开发的Node.js边缘计算项目,支持WebAssembly安全模式、完全兼容Node.js,并具有可插拔的JS引擎架构。
      • "Runs using WebAssembly when in --safe mode"
      • "It's fully compatible with Node.js (passing all their spec tests for non-VM modules)"
  2. 技术实现与疑问

    • 部分用户对技术实现细节表示疑惑,如是否能在浏览器前端运行、如何处理文件系统访问等。
      • "could you run this in frontend js using the browser's js engine and wasm environment similar to WebContainers?"
      • "how would you handle attempts to access to the file system or networking, is this already wired in somehow?"
  3. 潜在应用场景

    • 评论者探讨了Edge.js的潜在用途,如沙盒化用户生成的JS代码、在Electron应用中创建安全执行环境等。
      • "Could this be a way to sandbox user-generated JS in web apps?"
      • "Would edge.js be able (theoretically) to use electron's v8 to get a 'sanboxed within electron' execution environment?"
  4. 与其他技术的比较

    • 有用户将Edge.js与Deno、Firecracker等技术进行比较,讨论其优势和适用场景。
      • "I still prefer Deno because I don't need a separate npm install command"
      • "On cloud why is this better than firecracker, firecrack can run any programming language this is just nodejs"
  5. 安全性质疑

    • 部分评论者对Edge.js的安全模型提出疑问,特别是在处理恶意工作负载时的表现。
      • "Curious how this holds up under hostile workloads, especially with native modules and libuv in the mix."
      • "This feels like shifting the trust boundary from the OS (containers) into your runtime"
  6. 部署与集成

    • 有用户询问Edge.js是否支持与Caddy插件集成,以及是否适合作为Web应用的部署单元。
      • "would edge.js allow integrating with a caddy plug-in to handle serving the app from wasm?"
      • "getting wasm to be the unit of deployment/packaging for web apps"
  7. 技术细节探讨

    • 关于JS引擎选择和WebAssembly实现的讨论。
      • "can Edge.js use Wasmer? Or have you managed to compile V8/JSC into WebAssembly and are executing it with Wasmer?"
  8. 使用便捷性

    • 有用户比较了Edge.js和Deno在使用便捷性方面的差异。
      • "I still prefer Deno because I don't need a separate npm install command"
      • "Being able to import from URL and just running code without having to worry about scaffolding node_modules"

总结:评论主要围绕Edge.js的技术特点、潜在应用、安全性以及与其他技术的比较展开讨论,既有对其创新性的赞赏,也有对具体实现细节和使用场景的疑问。