{ "type": "module", "source": "doc/api/wasi.md", "modules": [ { "textRaw": "WebAssembly System Interface (WASI)", "name": "webassembly_system_interface_(wasi)", "introduced_in": "v12.16.0", "stability": 1, "stabilityText": "Experimental", "desc": "

The WASI API provides an implementation of the WebAssembly System Interface\nspecification. WASI gives sandboxed WebAssembly applications access to the\nunderlying operating system via a collection of POSIX-like functions.

\n
'use strict';\nconst fs = require('fs');\nconst { WASI } = require('wasi');\nconst wasi = new WASI({\n  args: process.argv,\n  env: process.env,\n  preopens: {\n    '/sandbox': '/some/real/path/that/wasm/can/access'\n  }\n});\nconst importObject = { wasi_snapshot_preview1: wasi.wasiImport };\n\n(async () => {\n  const wasm = await WebAssembly.compile(fs.readFileSync('./binary.wasm'));\n  const instance = await WebAssembly.instantiate(wasm, importObject);\n\n  wasi.start(instance);\n})();\n
\n

The --experimental-wasi-unstable-preview1 and --experimental-wasm-bigint\nCLI arguments are needed for the previous example to run.

", "modules": [ { "textRaw": "Class: `WASI`", "name": "class:_`wasi`", "meta": { "added": [ "v12.16.0" ], "changes": [] }, "desc": "

The WASI class provides the WASI system call API and additional convenience\nmethods for working with WASI-based applications. Each WASI instance\nrepresents a distinct sandbox environment. For security purposes, each WASI\ninstance must have its command line arguments, environment variables, and\nsandbox directory structure configured explicitly.

", "modules": [ { "textRaw": "`new WASI([options])`", "name": "`new_wasi([options])`", "meta": { "added": [ "v12.16.0" ], "changes": [] }, "desc": "", "type": "module", "displayName": "`new WASI([options])`" }, { "textRaw": "`wasi.start(instance)`", "name": "`wasi.start(instance)`", "meta": { "added": [ "v12.16.0" ], "changes": [] }, "desc": "\n

Attempt to begin execution of instance by invoking its _start() export.\nIf instance does not contain a _start() export, then start() attempts to\ninvoke the __wasi_unstable_reactor_start() export. If neither of those exports\nis present on instance, then start() does nothing.

\n

start() requires that instance exports a WebAssembly.Memory named\nmemory. If instance does not have a memory export an exception is thrown.

", "type": "module", "displayName": "`wasi.start(instance)`" }, { "textRaw": "`wasi.wasiImport`", "name": "`wasi.wasiimport`", "meta": { "added": [ "v12.16.0" ], "changes": [] }, "desc": "\n

wasiImport is an object that implements the WASI system call API. This object\nshould be passed as the wasi_snapshot_preview1 import during the instantiation\nof a WebAssembly.Instance.

", "type": "module", "displayName": "`wasi.wasiImport`" } ], "type": "module", "displayName": "Class: `WASI`" } ], "type": "module", "displayName": "WebAssembly System Interface (WASI)" } ] }