# Terminal and large files

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

## A wss:// URL for an interactive terminal (PTY) in the sandbox[#]

POST`/v1/sandboxes/{id}/terminal`scope sandboxes:write

The terminal is a fresh container from the sandbox's image with /workspace mounted. Binary WebSocket messages are keys in and output out; text messages are JSON: {type: "resize", cols, rows} in, {type: "exit", code} out. A sleeping sandbox is woken first.

Parameters

`id`requiredpath · string

Sandbox id (sbx_…)

JSON body

`cols`integer

Min 1. Max 1000.

`rows`integer

Min 1. Max 1000.

`command`array of string

Run this instead of a login shell, e.g. ["python3"]

Responses

200400401403404409501

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

## A presigned URL for one download (GET) or upload (PUT) of one path, straight to the host[#]

POST`/v1/sandboxes/{id}/files/link`scope sandboxes:read

PUT links need sandboxes:write. No size cap but the sandbox's disk (4 GiB per upload). A sleeping sandbox is woken first; a link used after it falls asleep again answers 409 use_api.

Parameters

`id`requiredpath · string

Sandbox id (sbx_…)

JSON body

`path`requiredstring

—

`method`"GET" | "PUT"

—

`ttl_s`integer

Min 10. Max 300.

Responses

200400401403404409501

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

## The file's bytes, streamed (the same as GET …/files on a host that streams)[#]

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

Parameters

`id`requiredpath · string

Sandbox id (sbx_…)

`path`requiredquery · string

An absolute path in the sandbox such as /workspace/data.csv or /tmp/out.bin (no ..)

`Range`header · string

One byte range (bytes=a-b, a-, -n): 206 with Content-Range, 416 past the end

Responses

200400401403404409416501

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

## Write the request body to the file, streamed (the same as PUT …/files on a host that streams)[#]

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

Through this API an upload is bounded by the request size Cloudflare allows (100 MB on most plans); past that, send parts with offset=, or PUT to the direct files_url or a PUT link, which go to the host straight (4 GiB a request).

Parameters

`id`requiredpath · string

Sandbox id (sbx_…)

`path`requiredquery · string

An absolute path in the sandbox such as /workspace/data.csv or /tmp/out.bin (no ..)

`offset`query · integer

Write the body at this byte; the rest of the file is kept and it grows as needed

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

Add the body at the end (not with offset)

`mode`query · string

Permission bits, octal

Body

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

Responses

200400401403404409413501507

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

---
Source: https://docs.kosa8.com/api/terminal-and-large-files/
