Skip to main content
Perform file operations on files and directories inside a running sandbox.

Base URL

All file operations use the sandbox’s public_host:
{sandbox_public_host}/files/{operation}

Authentication

Authorization: Bearer {auth_token}

Endpoints

Read File

GET /files/read?path=/workspace/file.txt
cURL:
curl -H "Authorization: Bearer {auth_token}" \
     "https://1761048129dsaqav4n.hopx.dev/files/read?path=/workspace/file.txt"
Python:
import requests

response = requests.get(
    f"{sandbox_public_host}/files/read",
    headers={"Authorization": f"Bearer {auth_token}"},
    params={"path": "/workspace/file.txt"}
)
content = response.json()["content"]
JavaScript:
const response = await fetch(
  `${sandboxPublicHost}/files/read?path=${encodeURIComponent('/workspace/file.txt')}`,
  {
    headers: {
      'Authorization': `Bearer ${authToken}`
    }
  }
);
const data = await response.json();
const content = data.content;

Write File

POST /files/write
Request Body:
{
  "path": "/workspace/file.txt",
  "content": "Hello, World!",
  "mode": "0644"
}
cURL:
curl -X POST https://1761048129dsaqav4n.hopx.dev/files/write \
  -H "Authorization: Bearer {auth_token}" \
  -H "Content-Type: application/json" \
  -d '{
    "path": "/workspace/file.txt",
    "content": "Hello, World!"
  }'
Python:
data = {
    "path": "/workspace/file.txt",
    "content": "Hello, World!",
    "mode": "0644"
}

response = requests.post(
    f"{sandbox_public_host}/files/write",
    headers={"Authorization": f"Bearer {auth_token}"},
    json=data
)
JavaScript:
await fetch(`${sandboxPublicHost}/files/write`, {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${authToken}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    path: '/workspace/file.txt',
    content: 'Hello, World!'
  })
});

List Directory

GET /files/list?path=/workspace
cURL:
curl -H "Authorization: Bearer {auth_token}" \
     "https://1761048129dsaqav4n.hopx.dev/files/list?path=/workspace"
Python:
response = requests.get(
    f"{sandbox_public_host}/files/list",
    headers={"Authorization": f"Bearer {auth_token}"},
    params={"path": "/workspace"}
)
files = response.json()["files"]
JavaScript:
const response = await fetch(
  `${sandboxPublicHost}/files/list?path=${encodeURIComponent('/workspace')}`,
  {
    headers: {
      'Authorization': `Bearer ${authToken}`
    }
  }
);
const data = await response.json();
const files = data.files;

Upload File

POST /files/upload
Content-Type: multipart/form-data
cURL:
curl -X POST https://1761048129dsaqav4n.hopx.dev/files/upload \
  -H "Authorization: Bearer {auth_token}" \
  -F "file=@local_file.txt" \
  -F "path=/workspace/remote_file.txt"
Python:
with open('local_file.txt', 'rb') as f:
    files = {'file': f}
    data = {'path': '/workspace/remote_file.txt'}
    response = requests.post(
        f"{sandbox_public_host}/files/upload",
        headers={"Authorization": f"Bearer {auth_token}"},
        files=files,
        data=data
    )

Download File

GET /files/download?path=/workspace/file.txt
cURL:
curl -H "Authorization: Bearer {auth_token}" \
     "https://1761048129dsaqav4n.hopx.dev/files/download?path=/workspace/file.txt" \
     -o downloaded_file.txt
Python:
response = requests.get(
    f"{sandbox_public_host}/files/download",
    headers={"Authorization": f"Bearer {auth_token}"},
    params={"path": "/workspace/file.txt"}
)
with open('downloaded_file.txt', 'wb') as f:
    f.write(response.content)
JavaScript:
const response = await fetch(
  `${sandboxPublicHost}/files/download?path=${encodeURIComponent('/workspace/file.txt')}`,
  {
    headers: {
      'Authorization': `Bearer ${authToken}`
    }
  }
);
const blob = await response.blob();
// Save blob to file