WASI enables WebAssembly programs to call standard library functions in the host operating system. It does so through a fine-grained security model known as “capability-based security”. The WebAssembly VM owner can grant access to host system resources when the VM starts up. The program cannot access any resources (e.g., file folders) that are not explicitly allowed.
Now, why limit ourselves to standard library functions? The same approach can be used to call just any host functions from WebAssembly. The Second State WebAssembly VM provides a WASI-like extension to access any command line programs in the host operating system.
The command line program can
- Take input via command line arguments, as well as the
- Return value and data via the
Application developers for the Second State VM (SSVM) can use our Rust interface crate to access this functionality. In
Cargo.toml, make sure that you have this dependency.
[dependencies] rust_process_interface_library = "0.1.3"
In the Rust application, you can now use the API methods to start a new process for the operating system command program, pass in arguments via the
arg() method as well as via the
STDIN, and receives the return values via the
let mut cmd = Command::new("http_proxy"); cmd.arg("post") .arg("https://api.sendgrid.com/v3/mail/send") .arg(auth_header); cmd.stdin_u8vec(payload.to_string().as_bytes()); let out = cmd.output();
The Rust function is then compiled into WebAssembly and can run in the SSVM.
To see the SSVM command and process interface in action, please check out the following tutorials.
http_proxycommand allows SSVM programs to make HTTP requests.
mobilenet_v2command allows SSVM programs to use the native Tensorflow library to execute MobileNet_V2 models.
mtcnncommand allows SSVM programs to use the native Tensorflow library to execute MTCNN models.
Note: The two Tensorflow examples serve as demonstrations on how the command and process interface works. For Tensorflow applications, SSVM has a special WASI-like extension for calling Tensorflow library functions on the host system. Check it out.