# Wasmer

**Wasmer** 是一个用 Rust 编写的开源 [WebAssembly](https://www.edgepedia.org/zh/webassembly) 运行时，它在轻量级、基于能力的沙箱中执行来自 Wasmer Registry 的 WebAssembly 模块和包。它既可作为命令行工具使用，也可直接嵌入 [JavaScript](https://www.edgepedia.org/zh/javascript)、Python、Rust 或 Swift 应用程序，同时它也是该公司无服务器云平台 Wasmer Edge 的底层支撑。<sup>[1](https://docs.wasmer.io/runtime/)</sup><sup> • </sup><sup>[2](https://github.com/wasmerio/wasmer)</sup>

| 关键事实 | 详情 |
|---|---|
| 是什么 | 一个 WebAssembly 运行时与沙箱引擎，MIT 许可，GitHub 星标 2.12 万<sup>[2](https://github.com/wasmerio/wasmer)</sup> |
| 公司 | Wasmer Inc.，成立于 2019 年；创始人兼 CEO 西鲁斯·阿克巴里（Syrus Akbary），GraphQL Python 社区的创建者<sup>[3](https://www.ycombinator.com/companies/wasmer)</sup> |
| 编译器后端 | Singlepass（编译快、内存占用低）、Cranelift（编译速度中等、运行时性能良好）、LLVM（编译慢、运行时性能极佳）<sup>[4](https://docs.wasmer.io/runtime/features/)</sup> |
| 引擎后端 | V8（用于 iOS、Android 和开发环境）与 Browser（在网页中客户端运行 Wasmer）<sup>[4](https://docs.wasmer.io/runtime/features/)</sup> |
| 安全模型 | 默认安全：除非显式启用，否则无文件、网络或环境访问权限<sup>[1](https://docs.wasmer.io/runtime/)</sup> |
| Wasmer Edge | 无服务器云平台，2023 年 6 月 15 日发布；应用从注册表中的包部署，并自动扩缩容<sup>[5](https://wasmer.io/posts/announcing-wasmer-edge)</sup> |

## 用途与安全模型

Wasmer 在基于能力的沙箱中运行 WebAssembly——一种可移植的二进制指令格式：除非宿主显式授予权限，否则模块无法对文件、网络或环境变量做任何操作。<sup>[1](https://docs.wasmer.io/runtime/)</sup> 这使它适合运行不受信任的或第三方代码，同一沙箱模型也延伸到在宿主应用程序内组合包、文件、环境变量、网络和长时间运行的进程。<sup>[1](https://docs.wasmer.io/runtime/)</sup>

该运行时可直接运行来自其注册表的即用包，包括 Python（`python/python`）、兼容 Node.js 的 JavaScript 运行时（`wasmer/edgejs`）、Bash、PHP、PostgreSQL（`wasmer/pglite`）、SQLite 和 FFmpeg。<sup>[2](https://github.com/wasmerio/wasmer)</sup> 典型的调用方式是直接运行一个包，例如 `wasmer run python/python -- -c "print('Hello from Wasmer')"`，包会被下载并缓存以供后续运行使用。<sup>[2](https://github.com/wasmerio/wasmer)</sup>

## 执行后端

Wasmer 的后端按执行代码的方式分为两类。<sup>[4](https://docs.wasmer.io/runtime/features/)</sup>

**编译器后端**将 WebAssembly 编译为原生机器码，并直接在 CPU 上运行：

- **Singlepass**：单遍编译器，编译速度极快、内存占用低，被称为区块链智能合约的理想选择。<sup>[1](https://docs.wasmer.io/runtime/)</sup><sup> • </sup><sup>[4](https://docs.wasmer.io/runtime/features/)</sup>
- **Cranelift**：编译速度中等，运行时性能良好。<sup>[4](https://docs.wasmer.io/runtime/features/)</sup>
- **LLVM**：编译慢，但运行时性能极佳。<sup>[4](https://docs.wasmer.io/runtime/features/)</sup>

**引擎后端**将 WebAssembly 交给现有引擎执行，而不是自行编译。这让 Wasmer 能在不允许生成原生机器码的平台上运行，例如 iOS 或网页内部：V8 后端委托给 Google 的 V8 引擎，Browser 后端委托给浏览器自带的 WebAssembly 引擎。<sup>[4](https://docs.wasmer.io/runtime/features/)</sup> Browser 后端之所以存在，是因为浏览器内置的 `WebAssembly` API 只能运行裸模块，没有文件、标准输入输出、参数或环境；Wasmer 提供了缺失的操作系统层 WASIX，使完整的程序（如 CLI 工具或 Python 解释器）可以完全在客户端运行。<sup>[4](https://docs.wasmer.io/runtime/features/)</sup>

后端支持因平台而异。编译器后端可在 Linux、macOS、Windows 和 Android 上运行，但不支持 iOS 或浏览器；而 V8 和 Browser 后端则覆盖 iOS 和浏览器。在指令集方面，Cranelift 和 Singlepass 支持 x86_64、arm64 和 riscv64gc，LLVM 还额外支持 loongarch64。<sup>[4](https://docs.wasmer.io/runtime/features/)</sup>

## WebAssembly 特性与运行时能力

Wasmer 支持较新的 WebAssembly 提案，包括 SIMD、引用类型、线程、批量内存操作、多值返回以及非陷阱浮点到整数转换。<sup>[1](https://docs.wasmer.io/runtime/)</sup><sup> • </sup><sup>[4](https://docs.wasmer.io/runtime/features/)</sup> 各后端的支持并不一致：Singlepass 缺少 SIMD 和宽算术，其多值支持为实验性；尾调用仅在 LLVM 后端上受支持。<sup>[4](https://docs.wasmer.io/runtime/features/)</sup>

除标准执行外，Wasmer 还提供缓存，使编译后的模块可在后续运行中以极短的启动时间复用；计量，即监控计算时间和其他资源并设置限制，也称为 gas 计量；以及性能分析，可生成可用 Linux perf 等工具分析的剖析数据。<sup>[4](https://docs.wasmer.io/runtime/features/)</sup>

## 接口与 SDK

三种接口共享相同的包和 WASIX 运行时：面向终端和脚本的 Wasmer CLI、面向 Node.js 和浏览器的 JavaScript SDK（`npm install @wasmer/sdk`），以及面向 Python 应用和 AI 智能体的 Python SDK（`python -m pip install wasmer-sdk`）。<sup>[1](https://docs.wasmer.io/runtime/)</sup> Swift SDK 支持 macOS 12+ 和 iOS，Rust SDK 可作为源码依赖使用。<sup>[2](https://github.com/wasmerio/wasmer)</sup> SDK 作为宿主应用程序的一部分在本地运行沙箱，无需 Docker 守护进程、无需启动虚拟机、无需远程沙箱服务；Wasmer 报告沙箱创建时间为 0.1 毫秒，命令运行速度比 Docker 和远程沙箱方案快 10 到 20 倍，启动速度快 2 到 10 倍。<sup>[6](https://wasmer.io/posts/wasmer-local-sandboxes-for-ai-agents)</sup> 同一个 JavaScript SDK 可以完全在浏览器中运行 Python、PHP 和 Next.js 服务器，每个运行时在首次使用时需下载约 50 至 70 MB 的未压缩内容。<sup>[6](https://wasmer.io/posts/wasmer-local-sandboxes-for-ai-agents)</sup>

## Wasmer Edge

Wasmer Edge 于 2023 年 6 月 15 日发布，是一个由 WebAssembly、Wasmer 和 WASIX 驱动的云平台，可在无需修改应用程序或代码库的情况下以无服务器模式运行典型的云应用。<sup>[5](https://wasmer.io/posts/announcing-wasmer-edge)</sup> 应用是主要的部署机制：每个应用基于一个注册表包，该包必须提供 HTTP 服务器，并按需自动扩缩容，以从距用户最近的边缘节点为请求提供服务。<sup>[7](https://docs.wasmer.io/edge/learn/apps/)</sup> 应用实例是无状态且短暂的，启动以服务请求，在短暂空闲后关闭，每个应用可通过自动分配的 `NAME.wasmer.app` 形式的 URL 访问。<sup>[7](https://docs.wasmer.io/edge/learn/apps/)</sup> 每次部署都会创建一个带有独立版本 URL 的新应用版本，因此可以在正式发布前测试更改，并轻松回滚。<sup>[7](https://docs.wasmer.io/edge/learn/apps/)</sup>

该平台的架构以 Wasmer Runtime 作为核心虚拟化层，运行时针对异步线程、完整的 POSIX 虚拟套接字、高工作负载密度、内存页共享和子进程进行了优化。<sup>[8](https://wasmer-docs.wasmer.app/edge/architecture/)</sup> 发布时，Wasmer 报告其自身的前端项目已运行在 Edge 上，这些项目从 Vercel 和 [Cloudflare Workers](https://www.edgepedia.org/zh/cloudflare-workers) 迁移而来，在此前一个月处理了超过 100 万次请求。<sup>[5](https://wasmer.io/posts/announcing-wasmer-edge)</sup>

## Edge.js 与边缘侧的 Node.js

Wasmer 自称是首个在边缘层提供完整 Node.js 的云托管服务商，其 CEO 西鲁斯·阿克巴里·涅托（Syrus Akbary Nieto）表示，该项目借助 AI 编码辅助仅用两周完成，而没有 AI 辅助估计需要一年。<sup>[9](https://openai.com/index/wasmer/)</sup>

## 性能对比

独立测量将 Wasmer 列为较快的 WebAssembly 运行时之一，结果取决于工作负载和后端。一项 2023 年的无服务器研究发现，对于最小哈希函数，Wasm 执行器分别达到 Docker 运行时吞吐量的 39%（wamr）、57%（Wasmtime）和 88%（Wasmer），而 Wasm 运行时整体峰值约为每秒 40 次请求，Docker 则不到 15 次，且相同内存下可常驻的函数数量是后者的 3.5 到 7.6 倍。<sup>[10](https://faculty.washington.edu/wlloyd/courses/tcss562_f2024/papers/2023/PushingServerlesstotheEdgewithWebAssemblyRuntimes.pdf)</sup> 一项 2026 年对 [Wasmtime](https://www.edgepedia.org/zh/wasmtime) 18.0、Wasmer 5.0 和 WasmEdge 0.14 的对比得出结论：没有单一运行时适合所有用例，Wasmer 5.0 因冷启动延迟低而在无服务器和短生命周期工作负载上表现最强。<sup>[11](https://www.johal.in/perf-test-wasmtime-180-vs-wasmer-50-vs)</sup> 已发表的对比普遍认为，Wasmtime 在标准支持方面领先，而 Wasmer 强调开箱即用、面向生产的功能集。<sup>[12](https://www.faun.dev/toolbox/wasmer-vs-wasmtime/)</sup>

## References

1. [Wasmer Runtime, Wasmer Docs](https://docs.wasmer.io/runtime/)
2. [wasmerio/wasmer on GitHub](https://github.com/wasmerio/wasmer)
3. [Wasmer, Y Combinator company profile](https://www.ycombinator.com/companies/wasmer)
4. [Wasmer Runtime Features, Wasmer Docs](https://docs.wasmer.io/runtime/features/)
5. [The Cloud is dead, long live the Cloud! Announcing Wasmer Edge, Wasmer Blog (June 15, 2023)](https://wasmer.io/posts/announcing-wasmer-edge)
6. [Wasmer SDK: Local Sandboxes for AI Agents, Wasmer Blog](https://wasmer.io/posts/wasmer-local-sandboxes-for-ai-agents)
7. [Wasmer Edge Apps, Wasmer Docs](https://docs.wasmer.io/edge/learn/apps/)
8. [Architecture of Wasmer Edge, Wasmer Docs](https://wasmer-docs.wasmer.app/edge/architecture/)
9. [How Wasmer used Codex to build a Node.js runtime for the edge, OpenAI (June 3, 2026)](https://openai.com/index/wasmer/)
10. [Pushing Serverless to the Edge with WebAssembly Runtimes (2023)](https://faculty.washington.edu/wlloyd/courses/tcss562_f2024/papers/2023/PushingServerlesstotheEdgewithWebAssemblyRuntimes.pdf)
11. [Perf Test: Wasmtime 18.0 vs. Wasmer 5.0 vs. WasmEdge 0.14, johal.in (April 2026)](https://www.johal.in/perf-test-wasmtime-180-vs-wasmer-50-vs)
12. [Wasmer vs Wasmtime: WebAssembly Runtimes Comparison (2026), Faun](https://www.faun.dev/toolbox/wasmer-vs-wasmtime/)

---
*Initially written Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 软件与编程 › Named software products and platforms › Cloud, virtualization, and containers › API management and serverless

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/wasmer

English original: https://www.edgepedia.org/wasmer
