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

# Rename / Move File

> Rename or move a file or directory inside a sandbox.

Renames or moves a file or directory from `old_path` to `new_path` inside the
sandbox. Works for both files and directories. If `new_path` is in a different
directory, this is equivalent to a move.

## Path Parameters

<ParamField path="sandbox_id" type="string" required>
  The sandbox identifier. Format: `sbx-<8 chars>`.
</ParamField>

## Request Body

<ParamField body="old_path" type="string" required>
  Current absolute path of the file or directory.

  Example: `"/home/user/draft.py"`
</ParamField>

<ParamField body="new_path" type="string" required>
  New absolute path (destination). Parent directories must already exist.

  Example: `"/home/user/final.py"`
</ParamField>

<ParamField body="username" type="string">
  Unix user performing the rename. Defaults to the envd default user.
</ParamField>

## Response

Returns the envd rename confirmation as a JSON object.

## Example

<CodeGroup>
  ```bash cURL theme={null}
  curl -X PATCH https://api.declaw.ai/sandboxes/sbx-a1b2c3d4/files \
    -H "X-API-Key: YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "old_path": "/home/user/draft.py",
      "new_path": "/home/user/final.py"
    }'
  ```

  ```python Python theme={null}
  from declaw import Sandbox

  sbx = Sandbox.connect("sbx-a1b2c3d4", api_key="YOUR_API_KEY", domain="api.declaw.ai")
  sbx.files.rename("/home/user/draft.py", "/home/user/final.py")
  ```

  ```typescript TypeScript theme={null}
  import { Sandbox } from "@declaw/sdk";

  const sbx = await Sandbox.connect("sbx-a1b2c3d4", {
    apiKey: "YOUR_API_KEY",
    domain: "api.declaw.ai",
  });
  await sbx.files.rename("/home/user/draft.py", "/home/user/final.py");
  ```
</CodeGroup>

## Error Responses

| Status | Cause                      |
| ------ | -------------------------- |
| `400`  | Invalid request body       |
| `401`  | Missing or invalid API key |
| `404`  | Sandbox not found          |
| `502`  | envd daemon unreachable    |
| `503`  | Sandbox has no VM          |
