WebAssembly Outside the Browser: Safely Running Untrusted Code
Photo: GitHub

WebAssembly Outside the Browser: Safely Running Untrusted Code

Although it was created for the web, WebAssembly is currently most useful on servers and in plugin systems.

WebAssembly is a binary format with two characteristics that rarely go hand in hand: it runs at nearly machine-code speed, and it is completely confined within a sandbox with no default privileges.

Why is the second characteristic the interesting one?

A WebAssembly module starts with only its own linear memory region and nothing else. No files, no network, no system clock—unless the host environment explicitly provides each of these.

This is exactly what you need when you want to run code written by someone else:

  • Plugin system — allows users to extend the software without worrying that plugins might secretly read files
  • Running code at the network edge — boots in less than a millisecond, much lighter than containers
  • Embed customer logic into a shared multi-tenant service

System Interface

Since WebAssembly itself has no concept of files or sockets, a standard is needed to specify how the host environment should grant permissions. This standard is based on the principle of permission delegation: modules cannot access any directories other than those that have already been granted to them.

Nothing has been settled yet

Calling back and forth between the module and the host environment is still costly when complex data structures need to be transferred. Multithreading and garbage collection support are still being refined. The language has a heavy runtime that compiles into fairly large modules.

Choose WebAssembly when your goal is to "run code I don't trust," not when you need better performance—there are usually simpler ways to achieve that.
Chia sẻ

Thảo luận