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

# Check File Exists

> Check if a file or directory exists in the sandbox using the HopX VM Agent API. Verify file existence before reading or writing, check directory presence, and handle missing files gracefully. Learn how to use GET /files/exists endpoint to check file existence. Includes request examples and error handling.

Check if a file or directory exists before reading or writing. Useful for conditional logic and error prevention.

## Endpoint

```
GET /files/exists
```

## Request

### Headers

```
Authorization: Bearer YOUR_JWT_TOKEN
```

### Query Parameters

| Parameter | Type   | Required | Description   |
| --------- | ------ | -------- | ------------- |
| `path`    | string | Yes      | Path to check |

### Example Request

```bash theme={null}
curl "https://sandbox_abc123xyz.hopx.dev/files/exists?path=/workspace/data.txt" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"
```

## Response

### Success (200 OK)

```json theme={null}
{
  "exists": true,
  "path": "/workspace/data.txt"
}
```

## Status Codes

| Code | Description                       |
| ---- | --------------------------------- |
| 200  | Success (exists is true or false) |
| 401  | Unauthorized                      |

## Use Cases

### Conditional Read

```bash theme={null}
#!/bin/bash
EXISTS=$(curl -s "https://sandbox_abc123xyz.hopx.dev/files/exists?path=/workspace/config.json" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" | jq -r '.exists')

if [ "$EXISTS" == "true" ]; then
  curl "https://sandbox_abc123xyz.hopx.dev/files/read?path=/workspace/config.json" \
    -H "Authorization: Bearer YOUR_JWT_TOKEN"
else
  echo "Config file not found"
fi
```

## Related

* **SDK**: [sandbox.files.exists()](/sdk/python/files#exists) - Python SDK method
* [CLI File Operations](/cli/commands/files) - File operations from CLI

## Next Steps

* **[Read File](/api/vm-agent/read-file)** - Read file if exists
* **[Write File](/api/vm-agent/write-file)** - Create file
