# Code interpreter

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.

## Run a Python cell in a stateful context: globals persist between calls, charts come back as images[#]

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

Needs a persistent sandbox (409 not_persistent otherwise) whose image has python3 (409 no_python). Runs through exec: a sleeping sandbox is woken first, with the same payment checks.

Parameters

`id`requiredpath · string

Sandbox id (sbx_…)

JSON body

`code`requiredstring

Max length 40960.

`language`"python"

—

`context`string

Default "default"; started on first use

`timeout_s`number

Default 30. Past it the cell is interrupted (TimeoutError) and the context lives on Min 0. Max 80.

Responses

200400401403404409502504

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

## The sandbox's running code contexts[#]

GET`/v1/sandboxes/{id}/code/contexts`scope sandboxes:write

Needs a persistent sandbox (409 not_persistent otherwise) whose image has python3 (409 no_python). Runs through exec: a sleeping sandbox is woken first, with the same payment checks.

Parameters

`id`requiredpath · string

Sandbox id (sbx_…)

Responses

200401403404409

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

## Start a context (its own globals)[#]

POST`/v1/sandboxes/{id}/code/contexts`scope sandboxes:write

Needs a persistent sandbox (409 not_persistent otherwise) whose image has python3 (409 no_python). Runs through exec: a sleeping sandbox is woken first, with the same payment checks.

Parameters

`id`requiredpath · string

Sandbox id (sbx_…)

JSON body

`name`string

—

Responses

201400401403404409

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

## Forget a context's globals[#]

POST`/v1/sandboxes/{id}/code/contexts/{name}/reset`scope sandboxes:write

Parameters

`id`requiredpath · string

Sandbox id (sbx_…)

`name`requiredpath · string

Context name: 1-32 of a-z, 0-9 and -

Responses

200401403404409

```
curl -s -X POST https://api.kosa8.com/v1/sandboxes/$SBX/code/contexts/$NAME/reset \
  -H "Authorization: Bearer $KOSA8_API_KEY"
```

## End a context's process[#]

DELETE`/v1/sandboxes/{id}/code/contexts/{name}`scope sandboxes:write

Parameters

`id`requiredpath · string

Sandbox id (sbx_…)

`name`requiredpath · string

Context name: 1-32 of a-z, 0-9 and -

Responses

200401403404409

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

---
Source: https://docs.kosa8.com/api/code-interpreter/
