# Sandbox files

5 endpoints at `https://api.kosa8.com`, sent with `Authorization: Bearer $KOSA8_API_KEY`. Generated from the API's own [OpenAPI description](https://api.kosa8.com/openapi.json), which a test holds to the router.

## Download a file, streamed; a sleeping sandbox wakes first[#]

GET`/v1/sandboxes/{id}/files`scope sandboxes:read

The bytes stream between the caller and the sandbox, never held whole on the way, so a file has no size cap but the sandbox's disk (4 GiB a request). Any absolute path: /workspace, which lasts across sleep and snapshots, or anywhere else in the sandbox's container (/tmp, /root, /home/…), the filesystem its commands see.

Parameters

`id`requiredpath · string

Sandbox id (sbx_…)

`path`requiredquery · string

An absolute path in the sandbox, e.g. /workspace/app.py, /tmp/out.bin or /root/.bashrc (a relative path is relative to /workspace; no ..)

`Range`header · string

One byte range, bytes=a-b, a- or -n: the answer is 206 with Content-Range, or 416 past the end

Responses

200400401402403404409413416501502

```
curl -s -X GET https://api.kosa8.com/v1/sandboxes/$SBX/files \
  -H "Authorization: Bearer $KOSA8_API_KEY"
```

## Upload a file (the body, any bytes), streamed[#]

PUT`/v1/sandboxes/{id}/files`scope sandboxes:write

The bytes stream between the caller and the sandbox, never held whole on the way, so a file has no size cap but the sandbox's disk (4 GiB a request). Any absolute path: /workspace, which lasts across sleep and snapshots, or anywhere else in the sandbox's container (/tmp, /root, /home/…), the filesystem its commands see. Through this API one request body is at most 100 MB (Cloudflare's limit): send a bigger file in parts with offset=, or PUT it to the direct files_url (POST …/direct) or a PUT link (POST …/files/link), which go to the host straight.

Parameters

`id`requiredpath · string

Sandbox id (sbx_…)

`path`requiredquery · string

An absolute path in the sandbox, e.g. /workspace/app.py, /tmp/out.bin or /root/.bashrc (a relative path is relative to /workspace; no ..)

`offset`query · integer

Write the body at this byte, keeping the rest of the file and growing it as needed: parts of a big upload, in any order or in parallel

`append`query · "1" | "true"

Add the body at the end of the file (not with offset)

`mode`query · string

Permission bits, octal, e.g. 755

Body

`application/octet-stream`: the raw bytes.

Responses

200400401402403404409413501502507

```
curl -s -X PUT https://api.kosa8.com/v1/sandboxes/$SBX/files \
  -H "Authorization: Bearer $KOSA8_API_KEY" \
  --data-binary @file
```

## Remove a file, or a folder with recursive=1[#]

DELETE`/v1/sandboxes/{id}/files`scope sandboxes:write

Parameters

`id`requiredpath · string

Sandbox id (sbx_…)

`path`requiredquery · string

An absolute path in the sandbox, e.g. /workspace/app.py, /tmp/out.bin or /root/.bashrc (a relative path is relative to /workspace; no ..)

`recursive`query · "1" | "true"

Remove a folder and everything in it

Responses

200400401402403404409501502

```
curl -s -X DELETE https://api.kosa8.com/v1/sandboxes/$SBX/files \
  -H "Authorization: Bearer $KOSA8_API_KEY"
```

## List a folder (default /workspace)[#]

GET`/v1/sandboxes/{id}/files/list`scope sandboxes:read

Parameters

`id`requiredpath · string

Sandbox id (sbx_…)

`path`query · string

Folder; default /workspace

Responses

200400401402403404409501502

```
curl -s -X GET https://api.kosa8.com/v1/sandboxes/$SBX/files/list \
  -H "Authorization: Bearer $KOSA8_API_KEY"
```

## Make a folder (and its parents)[#]

POST`/v1/sandboxes/{id}/files/mkdir`scope sandboxes:write

Parameters

`id`requiredpath · string

Sandbox id (sbx_…)

JSON body

`path`requiredstring

—

Responses

200400401402403404409501502

```
curl -s -X POST https://api.kosa8.com/v1/sandboxes/$SBX/files/mkdir \
  -H "Authorization: Bearer $KOSA8_API_KEY" \
  -H 'Content-Type: application/json' -d @body.json
```

---
Source: https://docs.kosa8.com/api/sandbox-files/
