> ## 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.

# How It Works

> Safely executing code, one request at a time

The Code Interpreter API lets you [execute untrusted
code](/api-reference/command/execute-code) in a few lines of code.

<CodeGroup>
  ```js Node theme={null}
  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();
  ```

  ```py Python theme={null}
  from rizaio import Riza

  client = Riza()

  resp = client.command.exec(
      language="python",
      code="print('Hello, world!')",
  )

  print(resp.stdout)
  ```

  ```go Go theme={null}
  package main

  import (
      "context"
      "log"

      "github.com/riza-io/riza-api-go"
  )

  func main() {
      client := riza.NewClient()
      resp, err := client.Command.Exec(context.Background(), riza.CommandExecParams{
          Language: riza.F(riza.CommandExecParamsLanguagePython),
          Code:     riza.F("print('Hello, world!')"),
      })
      if err != nil {
          log.Fatal(err)
      }
      log.Println(resp.Stdout)
  }
  ```

  ```bash curl  theme={null}
  curl https://api.riza.io/v1/execute \
  -H "Authorization: Bearer $RIZA_API_KEY" \
  -H "Content-Type: application/json; charset=utf-8" \
  --data-binary @- << EOF
  {
      "language": "python",
      "code": "print('Hello, world!')"
  }
  EOF
  ```
</CodeGroup>

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

<Steps>
  <Step title="Receive request">
    Your application makes a request to [https://api.riza.io](/api-reference/) with
    the code to execute and any [input](/reference/input) data.
  </Step>

  <Step title="Validate data">
    We validate that the incoming code and data don't violate
    [resource limits](/reference/limits).
  </Step>

  <Step title="Load WebAssembly">
    We load the compiled WebAssembly binary for the selected interpreter into
    memory. For most requests this step is cached.
  </Step>

  <Step title="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.
  </Step>

  <Step title="Execute code">
    We execute the code from your request within the WebAssembly module.
  </Step>

  <Step title="Return response">
    We return [`stdout` and `stderr`](/reference/output) from the execution,
    along with the program's exit code.
  </Step>
</Steps>
