> ## Documentation Index
> Fetch the complete documentation index at: https://docs.riza.io/llms.txt
> Use this file to discover all available pages before exploring further.

# JavaScript

> Execute JavaScript or TypeScript in a secure and isolated runtime environment

<Note>
  This page is about the JavaScript interpreter
  environment inside the Riza Code Interpreter API.
  If you're looking to call the API from Node,
  head over to the [API Client Libraries](/getting-started/client-libraries) page.
</Note>

The environment your JavaScript or TypeScript runs in depends on the [underlying Riza
environment](/interpreters/introduction) associated with your
runtime.

By default JavaScript runs in our highly-performant WASI environment. If you are
executing JavaScript in a [custom runtime](/getting-started/adding-packages), then your
JavaScript runs in our microVM environment unless you've opted-in to our new V8 environment
(in beta).

## Runtime

Within our default WASI environment we run [StarlingMonkey](https://github.com/bytecodealliance/StarlingMonkey)
compiled to WASM. This is a browser-based runtime that includes most standard browser builtins including
`fetch`, `JSON.parse` and `JSON.stringify`. TypeScript transpilation is handled automatically using
[swc](https://github.com/swc-project/swc).

In our microVM
environment we run [Node.js 22.13.0](https://nodejs.org/docs/latest-v22.x/api/).

To add additional packages from npm, you'll need to build a custom runtime. See
[Adding Packages](/getting-started/adding-packages) for more information.

## Resource limits

There are no limitations beyond the general [limits](/reference/limits)
that apply to all Riza interpreter runtime environments.

See our [roadmap](/reference/roadmap) for planned future improvements.

## Standard I/O

You can write to `stdout` and `stderr` with the typical `console` functions. Directly
writing to `process.stdout` or `process.stderr` will not work within the default WASI
environment, but does work within our microVM environment.

```js theme={null}
console.log("Hello, World!");
console.dir({"foo": "bar"});
console.error("Something went wrong!");
```

You can read from `process.stdin`, `process.argv` and `process.env` to get input data.
Note that `process.stdin` is just a string in our WASI environment, not a stream as it
is in our microVM and V8 environments.

```js theme={null}
// Read from stdin
const input = await new Response(process.stdin).text();

// Read from argv
process.argv.forEach((a) => ...);

// Read from env
console.log(JSON.stringify(process.env));
```

Also note that within the WASI environment `process.argv` has *two* system arguments in the
array before user-supplied arguments, rather than one.

## Files

<Note>
  The filesystem is read-only in all environments.
</Note>

You can pass input files via the API using the `files` parameter in the WASI and V8
environments. This feature is not yet available in the microVM environment.

See the [Files reference](/reference/files) for more details.

## Accessing the network

<Note>
  Network access is blocked by default, so you need to allow traffic to
  individual hosts using the `http` request parameter. See the [HTTP](/reference/http)
  reference for a full example.
</Note>

### In the WASI environment

You can make HTTP requests using `fetch`. Protocols other
than HTTP are not supported, and code can't access the network directly.

```javascript theme={null}
const options = {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({foo: "bar"}),
};
const r = await fetch("https://httpbin.org/post", options);
const data = await r.json();
console.log(data.args.foo);
```

### In the microVM and V8 environments

You can access the network any way you like, but you'll need to set the (unfortunately
named in this context) `http` request parameter appropriately to allow traffic to specific
hosts.

However, note that host-specific network controls are not yet supported in the microVM
environment. You can only allow all network traffic.

```json theme={null}
"http": {"allow": [{"host": "*"}]}
```
