The Riza Code Interpreter API allows you to safely execute untrusted Python, JavaScript, Ruby or PHP in an isolated and secure sandbox, powered by WebAssembly.

Install a Client Library

We publish API client libraries for Python, Node and Go. We’ll use them for this example.

Get an API Key

All requests to the Riza API require authentication. You can get an API key from the Riza Dashboard.

Once you have an API key, set it as the value of an environment variable named RIZA_API_KEY.

export RIZA_API_KEY="<api-key-contents>"

Say “Hello”

Let’s write a simple script that prints “Hello, world!” using our Execute Code API. We’ll use Python for this example, but our Code Interpreter API also supports JavaScript, TypeScript, Ruby and PHP.

print('Hello, world!')

We’ll send this single-line Python script to the Riza API for execution, and print the output. The only required parameters are language and code.

You can use one of our published API client libraries to make this request from Node, Python or Go, or use curl if available in your shell.

Each example above should print Hello, world! to standard output. The API response will look like this:

{
  "exit_code": 0,
  "stdout": "Hello, world!\n",
  "stderr": ""
}

Execute a function and return a value

In our previous example, we executed a script as you might do in a shell. The only way to get a value back from the script is to print it to standard output as a string.

That’s a good start, but what if we want to return a value from a function? For this, we can use our Execute Function API.

This API supports Python, JavaScript, and TypeScript. It requires you to write your code in a specific way, with a function execute that takes a single argument input. Your function must also return a value that can be serialized to JSON.

Let’s write a simple function that prints “Hello, David!” and returns {"greeted": true}:

def execute(input):
    print(f"Hello, {input['name']}!")
    return {"name": input["name"], "greeted": True}

Here’s how we’d make this request to our Execute Function API:

The response will look like this:

{
  "output": { "name": "David", "greeted": true },
  "output_status": "valid",
  "execution": { "exit_code": 0, "stdout": "Hello, David!\n", "stderr": "" }
}

Next Steps