Announcing WebAssembly.sh

An online WebAssembly Terminal to run WASI modules directly on your browser

Aaron Turner
Oct 9 · 4 min read

Just last week we released Wasmer-JS, a collection of open-source installable packages for running WASI modules in Node and the browser.

📣 Today, with the back-to-back announcement, we are excited to announce WebAssembly.sh.

WebAssembly.sh online Terminal

WebAssembly.sh is an open-source and installable Progressive Web App (PWA) terminal fully powered by WebAssembly and Wasmer-JS, that uses the WebAssembly Package Manager and local files to run server-side Wasm WASI modules in a shell-like interface 🖥

We are stoked to share WebAssembly.sh, because we feel like it has a lot to offer for a variety of use cases:

  • WebAssembly.sh is a sandboxed way to quickly test or try a program that compiles to WASI without installing the binary on your local machine. 🏖️
  • Developers writing WASI modules can use WebAssembly.sh to debug and test them in the browser! 🛠️
  • People who want to have some fun can run Python with rustpython, get some colorful output with lolcat, or make a cow talk with cowsay 😂
  • And much more! 🤩

The goals of WASI go far beyond CLI-styled applications. However, the current API supports them and we are excited to introduce these use cases today for the community!

Let’s take a step back, and see how we can use WebAssembly.sh. 🤔

Using WebAssembly.sh

Let’s take a quick walkthrough of WebAssembly.sh.

On first load (~200KB) you will be greeted with a welcome message. But behind the scenes, all of the PWA magic happens. The service worker will be installed, and now WebAssembly.sh will work offline. 🤯

You will also notice WebAssembly.sh can be installed natively either through the “Add to HomeScreen” on mobile, or the install icon in the URL bar on Desktop browsers. All of this functionality can be confirmed and investigated through your browser’s developers tool. In particular we used Chrome’s Lighthouse Audit to help us build for / enable the PWA features in WebAssembly.sh. 💡

Lighthouse audit results for WebAssembly.sh

Let’s get started running some commands!

When WebAssembly.sh tries to run a command, first it will check if the WASI-compiled module is already installed and cached.
If not, WebAssembly.sh will default to searching on WAPM to then download and run that module. ⚡

Let’s say we take a look at the available WASI packages on WAPM, and we decide to run quickjs (docs) to evaluate Javascript through their WASI compiled engine. Thus, we would enter the command quickjs, and then you should be able to start using the engine!

Running QuickJS in WebAssembly.sh

Next, let’s upload and run our own custom WASI modules. For this, we can use the package manager for WebAssembly.sh, wapm.

️WAPM on WebAssembly.sh, is a command to manage Wasm Modules. It is intended to behave similar to the native WAPM Package Manager. Using the command wapm upload , a file upload dialog will show up, allowing you to upload your own .wasm file to be installed as a command. For example, if we install mywasi.wasm using wapm upload , then you can run the command mywasi to run the Wasm / WASI module.

Wapm also supports other functions such as: wapm install to manually install a package and/or a package version from Wapm, wapm list to list all available commands, and wapm uninstall to delete a command installed by Wapm. Another nice feature is that the commands installed by Wapm are saved to IndexedDB using idb-keyval so that installed modules work between sessions, and even work offline! 📦

Using the wapm CLI in WebAssembly.sh

We can also get Wasm modules to work with one another! Similar to a Unix environment, WebAssembly.sh supports piping. It uses Comlink in the background, to spin up multiple workers and passed standard input and standard output between them. Using the example we mentioned earlier in the article, we can run cowsay WebAssembly | lolcat , and we get a colorful cowsay shown in our terminal! 🐄🌈

Piping Cowsay into lolcat

With that short introduction, you should be able to hit the ground running with WebAssembly.sh! 🏃

Thank you!

We are super excited to see how people use WebAssembly.sh, and we hope you enjoy using it as much as we did making it. 😄

As mentioned in the Wasmer-JS announcement, this is possible due to a lot of awesome open source projects in the JavaScript and WebAssembly community. Another huge thank you to the authors of node-wasi, wasm-pack, memfs, Xterm.js, Comlink, and the other dependencies we are building on top of! 🙏

We are working to bring features like Filesystem Access (both in the browser using memfs, and natively through something like Electron), additional caching for more offline support, and much more!

Feel free to reach out on Twitter or Spectrum, and we are very excited to see what you build! Cheers! 🍻

Thanks to Syrus Akbary

Aaron Turner

Written by

Skate. Music. Video Games. Code. Developer / Developer Relations at Wasmer. All opinions expressed are my own. Please excuse the spelling, I am a lazy typist.

Wasmer

Wasmer

Universal WebAssembly runtime

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade