Skip to main content
Read file contents from the sandbox. Only allowed paths like /workspace and /tmp can be read.

Endpoint

GET /files/read

Request

Headers

Authorization: Bearer YOUR_JWT_TOKEN

Query Parameters

ParameterTypeRequiredDescription
pathstringYesFile path (e.g., /workspace/data.txt)

Example Request

curl "https://sandbox_abc123xyz.hopx.dev/files/read?path=/workspace/data.txt" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"

Response

Success (200 OK)

{
  "content": "Hello World\nLine 2\nLine 3\n",
  "path": "/workspace/data.txt",
  "size": 30
}

Response Fields

FieldTypeDescription
contentstringFile contents as text
pathstringFile path
sizeintegerFile size in bytes

Status Codes

CodeDescription
200Success
401Unauthorized
403Path not allowed (outside allowed directories)
404File not found

Errors

File Not Found (404)

{
  "error": "File not found: /workspace/nonexistent.txt",
  "code": "FILE_NOT_FOUND"
}
Cause: The file doesn’t exist. Fix: Verify the file path and ensure the file exists.

Path Not Allowed (403)

{
  "error": "Path not allowed: /etc/passwd",
  "code": "FORBIDDEN"
}
Cause: The path is outside allowed directories. Fix: Only read files from /workspace, /tmp, or other explicitly allowed paths.

Allowed Paths

You can read files from:
  • /workspace/* - Main working directory
  • /tmp/* - Temporary files
  • Other paths may be allowed depending on sandbox configuration

Use Cases

Read Configuration File

curl "https://sandbox_abc123xyz.hopx.dev/files/read?path=/workspace/config.json" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" | jq '.content | fromjson'

Read Log File

curl "https://sandbox_abc123xyz.hopx.dev/files/read?path=/workspace/app.log" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" | jq -r '.content'

Read CSV Data

curl "https://sandbox_abc123xyz.hopx.dev/files/read?path=/workspace/data.csv" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" | jq -r '.content' | head -10

Check File Size

curl "https://sandbox_abc123xyz.hopx.dev/files/read?path=/workspace/large_file.txt" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" | jq '.size'

Read and Process

import requests
import json

url = "https://sandbox_abc123xyz.hopx.dev/files/read"
headers = {"Authorization": "Bearer YOUR_JWT_TOKEN"}
params = {"path": "/workspace/results.json"}

response = requests.get(url, headers=headers, params=params)
data = response.json()

# Parse JSON content
file_content = json.loads(data["content"])
print(f"Read {data['size']} bytes from {data['path']}")
print(f"Data: {file_content}")

Next Steps