{
  "type": "module",
  "source": "doc/api/wasi.md",
  "modules": [
    {
      "textRaw": "WebAssembly System Interface (WASI)",
      "name": "webassembly_system_interface_(wasi)",
      "introduced_in": "v13.3.0",
      "stability": 1,
      "stabilityText": "Experimental",
      "desc": "<p>The WASI API provides an implementation of the <a href=\"https://wasi.dev/\">WebAssembly System Interface</a>\nspecification. WASI gives sandboxed WebAssembly applications access to the\nunderlying operating system via a collection of POSIX-like functions.</p>\n<pre><code class=\"language-js\">'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</code></pre>\n<p>The <code>--experimental-wasi-unstable-preview1</code> and <code>--experimental-wasm-bigint</code>\nCLI arguments are needed for the previous example to run.</p>",
      "modules": [
        {
          "textRaw": "Class: `WASI`",
          "name": "class:_`wasi`",
          "meta": {
            "added": [
              "v13.3.0"
            ],
            "changes": []
          },
          "desc": "<p>The <code>WASI</code> class provides the WASI system call API and additional convenience\nmethods for working with WASI-based applications. Each <code>WASI</code> instance\nrepresents a distinct sandbox environment. For security purposes, each <code>WASI</code>\ninstance must have its command line arguments, environment variables, and\nsandbox directory structure configured explicitly.</p>",
          "modules": [
            {
              "textRaw": "`new WASI([options])`",
              "name": "`new_wasi([options])`",
              "meta": {
                "added": [
                  "v13.3.0"
                ],
                "changes": []
              },
              "desc": "<ul>\n<li>\n<p><code>options</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object\" class=\"type\">&lt;Object&gt;</a></p>\n<ul>\n<li><code>args</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array\" class=\"type\">&lt;Array&gt;</a> An array of strings that the WebAssembly application will\nsee as command line arguments. The first argument is the virtual path to the\nWASI command itself. <strong>Default:</strong> <code>[]</code>.</li>\n<li><code>env</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object\" class=\"type\">&lt;Object&gt;</a> An object similar to <code>process.env</code> that the WebAssembly\napplication will see as its environment. <strong>Default:</strong> <code>{}</code>.</li>\n<li><code>preopens</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object\" class=\"type\">&lt;Object&gt;</a> This object represents the WebAssembly application's\nsandbox directory structure. The string keys of <code>preopens</code> are treated as\ndirectories within the sandbox. The corresponding values in <code>preopens</code> are\nthe real paths to those directories on the host machine.</li>\n</ul>\n</li>\n</ul>",
              "type": "module",
              "displayName": "`new WASI([options])`"
            },
            {
              "textRaw": "`wasi.start(instance)`",
              "name": "`wasi.start(instance)`",
              "meta": {
                "added": [
                  "v13.3.0"
                ],
                "changes": []
              },
              "desc": "<ul>\n<li><code>instance</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly.Instance\" class=\"type\">&lt;WebAssembly.Instance&gt;</a></li>\n</ul>\n<p>Attempt to begin execution of <code>instance</code> by invoking its <code>_start()</code> export.\nIf <code>instance</code> does not contain a <code>_start()</code> export, then <code>start()</code> attempts to\ninvoke the <code>__wasi_unstable_reactor_start()</code> export. If neither of those exports\nis present on <code>instance</code>, then <code>start()</code> does nothing.</p>\n<p><code>start()</code> requires that <code>instance</code> exports a <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory\"><code>WebAssembly.Memory</code></a> named\n<code>memory</code>. If <code>instance</code> does not have a <code>memory</code> export an exception is thrown.</p>",
              "type": "module",
              "displayName": "`wasi.start(instance)`"
            },
            {
              "textRaw": "`wasi.wasiImport`",
              "name": "`wasi.wasiimport`",
              "meta": {
                "added": [
                  "v13.3.0"
                ],
                "changes": []
              },
              "desc": "<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object\" class=\"type\">&lt;Object&gt;</a></li>\n</ul>\n<p><code>wasiImport</code> is an object that implements the WASI system call API. This object\nshould be passed as the <code>wasi_snapshot_preview1</code> import during the instantiation\nof a <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance\"><code>WebAssembly.Instance</code></a>.</p>",
              "type": "module",
              "displayName": "`wasi.wasiImport`"
            }
          ],
          "type": "module",
          "displayName": "Class: `WASI`"
        }
      ],
      "type": "module",
      "displayName": "WebAssembly System Interface (WASI)"
    }
  ]
}