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

# Files

> Working with files

Your script has limited access to the filesystem. Expanded access is on
our [roadmap](/reference/roadmap).

## The `files` request parameter

<Note>If you are operating on multiple files this is the best option.</Note>

The [execute code](/api-reference/command/execute-code) endpoint accepts a
`files` parameter which is a list of file objects. Each file object has a
`path` parameter and a `contents` parameter. Riza makes each file in the list
available at the specified path, relative to `/mnt/req/`.

For instance, if you pass the following `files` list to the API then your
script will have access to two files located at `/mnt/req/people.csv` and
`/mnt/req/img/riza.svg`.

```json theme={null}
{
  "files": [
    {"path": "people.csv", "contents": "Aaron,21,CA"},
    {"path": "img/riza.svg", "contents": "<?xml version="1.0" standalone="no"?><!DOCTYPE svg..."}
  ]
}
```

## `stdin` and `stdout`

<Note>If you only need to operate on a single file this may be the best option.</Note>

The [execute code](/api-reference/command/execute-code) endpoint accepts a string
`stdin` parameter. The API sets any value you provide as stdin for the executed
script.

You can encode the bytes of your file as a string (base64 encoding is a good choice)
and pass it to the API as the `stdin` parameter. Just remember to decode the bytes
you read from `stdin` within your script.

If you've manipulated the file and want to get it back, you can just do the reverse.
Encode the bytes of the file as a string within your script, and print to `stdout`.
The resulting string is available in the `stdout` parameter of the API response.

<RequestExample>
  ```js Node theme={null}
  import fs from 'node:fs';
  import Riza from '@riza-io/api';

  const pythonCode = `
  import sys
  import base64

  stdin = sys.stdin.read()
  decoded_stdin = base64.b64decode(stdin)

  # do something with the file...
  `;

  const fileContents = fs.readFileSync('/path/to/some/file', 'utf8');

  const riza = new Riza();

  async function main() {
    const resp = await riza.command.exec({
      language: "python",
      code: pythonCode,
      stdin: fileContents.toString('base64')
    });
    console.log(resp.stdout);
  }

  main();
  ```

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

  CODE = """
  import sys
  import base64

  stdin = sys.stdin.read()
  decoded_stdin = base64.b64decode(stdin)

  # do something with the file...
  """

  with open("/path/to/some/file") as f:
      file_contents = f.read()

  client = Riza()

  resp = client.command.exec(
      language="python",
      code=CODE,
      stdin=base64.b64encode(file_contents)
  )

  print(resp.stdout)
  ```

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

  import (
      "context"
      "encoding/base64"
      "log"
      "log/slog"
      "os"

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

  const pythonCode = `
  import sys
  import base64

  stdin = sys.stdin.read()
  file_contents = base64.b64decode(stdin)

  # do something with the file...
  `

  func main() {
      fileContents, _ := os.ReadFile("/path/to/some/file")
      client := riza.NewClient()
      params := riza.CommandExecParams{
          Language: riza.F(riza.CommandExecParamsLanguagePython),
          Code:     riza.F(pythonCode),
          Stdin:    riza.F(base64.StdEncoding.EncodeToString(fileContents)),
      }
      resp, err := client.Command.Exec(context.TODO(), params)
      if err != nil {
          log.Fatal(err)
      }
      slog.Info(
          resp.Stdout,
          "code", resp.ExitCode,
          "stderr", resp.Stderr,
      )
  }
  ```
</RequestExample>
