The Code Interpreter API lets you execute untrusted code in a few lines of code.

import Riza from '@riza-io/api';

const riza = new Riza();

async function main() {
  const resp = await riza.command.exec({
    language: "PYTHON",
    code: "print('Hello, world!')",
  });
  console.log(resp.stdout);
}

main();

But how do we actually safely execute that code? Here’s a brief explanation of how it works.

1

Receive request

Your application makes a request to https://api.riza.io with the code to execute and any input data.

2

Validate data

We validate that the incoming code and data don’t violate resource limits.

3

Load WebAssembly

We load the compiled WebAssembly binary for the selected interpreter into memory. For most requests this step is cached.

4

Create WebAssembly module

We instantiate a new WebAssembly module for the loaded interpreter. We set stdin, command line arguments and environment variables, and configure runtime resource limits.

5

Execute code

We execute the provided code from your request in the selected interpreter.

6

Return response

We return stdout and stderr from the execution, along with the program’s exit code.