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

# Change Owner

> Change the owning user and group of a path in a runtime (chown)

`POST /v1/agents/runtime/{runtime_id}/files/chown`

Changes the owning user and/or group of a path. Names are resolved inside the guest, so
both names (`root`, `www-data`) and numeric IDs (`0`, `33`) are accepted.

At least one of `user` or `group` must be supplied.

<CodeGroup>
  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  from gravixlayer import GravixLayer

  client = GravixLayer()  # defaults to cloud="aws", region="us-east-1"
  sandbox = client.runtime.create()  # defaults to template="base-small"

  sandbox.file.create_directory("/workspace/data")

  result = sandbox.file.chown("/workspace/data", user="root", group="root", recursive=True)
  print(result.success, result.path)

  sandbox.kill()
  ```

  ```typescript TypeScript theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import { GravixLayer } from 'gravixlayer';

  const client = new GravixLayer(); // defaults to cloud="aws", region="us-east-1"
  const sandbox = await client.runtime.create(); // defaults to template="base-small"

  await sandbox.file.createDirectory('/workspace/data');

  const result = await sandbox.file.chown('/workspace/data', {
    user: 'root',
    group: 'root',
    recursive: true,
  });
  console.log(result.success, result.path);

  await sandbox.kill();
  ```

  ```bash CLI theme={"theme":{"light":"github-light","dark":"github-dark"}}
  gravixlayer runtime files chown "$RT" /workspace/data --user root --group root --recursive
  ```

  ```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
  curl -X POST "https://api.gravixlayer.ai/v1/agents/runtime/$RT/files/chown" \
    -H "Authorization: Bearer $GRAVIXLAYER_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{"path": "/workspace/data", "user": "root", "group": "root", "recursive": true}'
  ```
</CodeGroup>

## Parameters

| Parameter   | Type    | Required | Description                                     |
| ----------- | ------- | -------- | ----------------------------------------------- |
| `path`      | string  | Yes      | File or directory path                          |
| `user`      | string  | No       | Owning user name or numeric UID                 |
| `group`     | string  | No       | Owning group name or numeric GID                |
| `recursive` | boolean | No       | Apply to the whole subtree. Defaults to `false` |

## Response (`ChangeOwnerResponse`)

| Field     | Type    | Description                     |
| --------- | ------- | ------------------------------- |
| `success` | boolean | Whether the operation succeeded |
| `path`    | string  | The path that was changed       |
| `message` | string  | Confirmation message            |

<Note>
  Changing ownership to another user requires privileges inside the guest. Templates that
  run as an unprivileged user can only chown paths they already own.
</Note>
