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

# File Exists

> Check whether a path exists inside a sandbox.

Checks whether a file or directory exists at the given path inside the sandbox.
Returns `{ "exists": true }` or `{ "exists": false }`.

Use this endpoint to guard against re-writing files that already exist, or to
verify that a command produced its expected output.

## Path Parameters

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

## Query Parameters

<ParamField query="path" type="string" required>
  Absolute path to check inside the sandbox.

  Example: `/home/user/script.py`
</ParamField>

## Response

<ResponseField name="exists" type="boolean">
  `true` if the path exists (as any entry type), `false` otherwise.
</ResponseField>

## Example

<CodeGroup>
  ```bash cURL theme={null}
  curl "https://api.declaw.ai/sandboxes/sbx-a1b2c3d4/files/exists?path=/home/user/script.py" \
    -H "X-API-Key: YOUR_API_KEY"
  ```

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

  sbx = Sandbox.connect("sbx-a1b2c3d4", api_key="YOUR_API_KEY", domain="api.declaw.ai")
  if sbx.files.exists("/home/user/output.csv"):
      content = sbx.files.read("/home/user/output.csv")
  ```

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

  const sbx = await Sandbox.connect("sbx-a1b2c3d4", {
    apiKey: "YOUR_API_KEY",
    domain: "api.declaw.ai",
  });
  const doesExist = await sbx.files.exists("/home/user/output.csv");
  if (doesExist) {
    const content = await sbx.files.read("/home/user/output.csv");
  }
  ```
</CodeGroup>

```json Response (exists) theme={null}
{
  "exists": true
}
```

```json Response (not found) theme={null}
{
  "exists": false
}
```

## Error Responses

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