The maintainer of this website has a Spotify Coding Playlist of their Lo-fi Hip Hop beats!

WebAssembly Logo

Wasm By Example

Language:

WASI Introduction

First, we should answer the question, "What is WASI"? The formal answer to this is: WASI is the WebAssembly System Interface, "a modular system interface for WebAssembly". To provide an easy introduction into why the idea of WASI is exciting, let's look at some possible use cases when the goals of WASI are met:

It is important to note These are high-level use-case examples, not all of these use cases can be done with the current version of WASI, and we will be covering how WASI is still in progress and being standardized. However, now that we have a high level idea of what WASI can unlock for developers, lets start diving into the details on how this works:

I also think it'd be worth getting some key terms out of the way. This will make it a lot easier to speak about using WebAssembly outside of the browser with WASI. And paint a fuller picture of what was just explained above:

The last thing worth mentioning is that WASI uses a capability based security model. Meaning, the host must explicitly grant a capability to a guest module in order for the guest module to perform an action. For example in Wasmtime, by default, the guest module cannot access any part of the host's filesystem. The user that invokes Wasmtime must pass in the --mapdir or --dir flag to grant modules the capability to access directories in the host filesystem.

At the time of this writing, a lot of WASI is still in proposals and things. Other system resources, like networking, are not yet part of the WASI standard, though they will be one day. So, if you're hoping to bind() to a socket in your WebAssembly module, WASI hosts don't yet expose those capabilities. Only a few features of what WASI is hoping to acheive is fully implemented and standardized. One of those features is filesystem access!

Therefore, let's take a look at modifying the file system in the WASI hello world example, if there is a hello world currently for your language. If not, feel free to look at your language documentation, to see if they support WASI currently, and submit the WASI hello world example for your language.