# kosa8 Cloud MCP server

kosa8 Cloud has a remote MCP server at `https://api.kosa8.com/mcp`. Connect your AI agent to it and it can create sealed cloud sandboxes, run commands in them, put them to sleep and delete them, with nothing installed on your machine. An app that supports OAuth needs only the URL: you sign in to kosa8 Cloud in the browser and choose what it may do. Anything else uses an API key.

## Connect with just the URL (OAuth)

Claude (claude.ai and the desktop app), ChatGPT, Claude Code, Codex and other clients that follow the MCP authorization spec sign in by themselves. Add a custom connector or remote MCP server with the URL `https://api.kosa8.com/mcp` and no key:

- **Claude**: Settings, Connectors, Add custom connector, and paste the URL.

- **ChatGPT**: Settings, Connectors (developer mode), Create, and paste the URL with OAuth as the authentication.

- **Claude Code**: `claude mcp add --transport http kosa8-cloud https://api.kosa8.com/mcp`, then `/mcp` and Authenticate.

- **Codex**: add `url = "https://api.kosa8.com/mcp"` under `[mcp_servers.kosa8-cloud]` in `~/.codex/config.toml` and run `codex mcp login kosa8-cloud`.

Your browser opens **app.kosa8.com**. Sign in (email and password, an emailed link, or SSO; not an API key), check the app's name and where it returns to, untick anything you do not want it to have, and press **Allow**. The app can do at most what your role can: a viewer can give `sandboxes:read` only.

| Permission | Lets the app |
|---|---|
| `sandboxes:read` | See your sandboxes, their files, logs and cost |
| `sandboxes:write` | Create, run commands in, sleep and delete sandboxes (this costs sandbox time) |
| `functions:invoke`, `functions:deploy`, `audit:read` | Only if the app asks for them |

What it gets is tied to you and your organization:

- An access token that lasts an hour and works only at `/mcp` (the REST API refuses it), and a refresh token that lasts 30 days and is replaced every time it is used. If a used refresh token ever comes back, kosa8 assumes it was copied and disconnects the app.

- It stops at once if you leave the organization, sign out everywhere, or change or reset your password. If your role is lowered, it keeps only what the new role holds, and stops if that is nothing. While the organization is frozen in the Security Center, connected apps stop.

- Every tool call is in **Audit** as you, with `via: mcp`; the connection itself is `oauth.authorize`.

- See and disconnect apps in the dashboard under **Keys & secrets, Connected apps** (owners and admins see everyone's), with `GET /v1/oauth/grants` and `DELETE /v1/oauth/grants/{id}`, or from the app, which revokes its token.

### For client developers: the OAuth details

- `POST /mcp` without a token answers `401` with `WWW-Authenticate: Bearer resource_metadata="https://api.kosa8.com/.well-known/oauth-protected-resource/mcp", scope="sandboxes:read sandboxes:write"`. The protected resource metadata (RFC 9728) is also at `/.well-known/oauth-protected-resource`.

- Authorization server metadata (RFC 8414): `https://api.kosa8.com/.well-known/oauth-authorization-server`. Issuer `https://api.kosa8.com`; the authorization endpoint is `https://app.kosa8.com/oauth/authorize`; token, registration and revocation are `/oauth/token`, `/oauth/register` and `/oauth/revoke` on the API.

- Dynamic client registration (RFC 7591). Redirect URIs must be https, http on `localhost`, `127.0.0.1` or `[::1]`, or an app's own scheme; no fragments. They are matched exactly, port included. `token_endpoint_auth_method` may be `none` (public clients), `client_secret_post` or `client_secret_basic` (the default when left out, as RFC 7591 says).

- Authorization code with PKCE: `S256` only, and `state` is required. A code lasts 60 seconds and works once; redeeming it twice revokes what the first redemption got.

- Send `resource=https://api.kosa8.com/mcp` (RFC 8707) on the authorization and token requests. Unknown scopes (such as `offline_access`) are ignored; a refresh token is always issued. A refresh may narrow `scope`, never widen it.

- Client ID Metadata Documents (a URL as `client_id`) are not supported yet, so the metadata has no `client_id_metadata_document_supported`; clients fall back to dynamic client registration, as the MCP spec describes.

## Connect with an API key

For a client without OAuth, or a script, you need a kosa8 Cloud API key ([kosa8 Cloud](https://docs.kosa8.com/guides/cloud/) shows how to get one). Give the agent its own key with the `sandboxes:write` scope, so you can revoke it without touching your other keys. Then put it in your shell:

```
$ export KOSA8_API_KEY=k8c_live_…
```

### Claude Code

```
$ claude mcp add --transport http --scope user kosa8-cloud https://api.kosa8.com/mcp --header "Authorization: Bearer $KOSA8_API_KEY"
```

The shell fills in the key, so Claude Code stores the key itself. `--scope user` makes it available in every project; leave it out to add it to this project only. Check it with `claude mcp list`, or `/mcp` inside Claude Code.

### Cursor

Add this to `~/.cursor/mcp.json` (every project) or `.cursor/mcp.json` in one project. Cursor fills in `${env:KOSA8_API_KEY}` from its environment, so the key is not written into the file:

```
{
  "mcpServers": {
    "kosa8-cloud": {
      "url": "https://api.kosa8.com/mcp",
      "headers": { "Authorization": "Bearer ${env:KOSA8_API_KEY}" }
    }
  }
}
```

Cursor has to see the variable: on macOS an app opened from the Dock does not get your shell's variables, so start Cursor from a terminal where it is set, or put the key itself in the file with `kosa8 cloud mcp --install cursor` (below).

### Codex

Add this to `~/.codex/config.toml`. Codex sends the key it reads from `KOSA8_API_KEY` as the bearer token:

```
[mcp_servers.kosa8-cloud]
url = "https://api.kosa8.com/mcp"
bearer_token_env_var = "KOSA8_API_KEY"
```

### Any other MCP client

The server speaks the MCP **Streamable HTTP** transport (protocol versions 2025-03-26, 2025-06-18 and 2025-11-25). Point the client at:

| URL | `https://api.kosa8.com/mcp` |
|---|---|
| Header | `Authorization: Bearer k8c_live_…` |

A client that only starts local (stdio) servers, such as Claude Desktop's config file, can reach it through the `mcp-remote` bridge (needs Node.js):

```
{
  "mcpServers": {
    "kosa8-cloud": {
      "command": "npx",
      "args": ["-y", "mcp-remote", "https://api.kosa8.com/mcp", "--header", "Authorization:${KOSA8_AUTH_HEADER}"],
      "env": { "KOSA8_AUTH_HEADER": "Bearer k8c_live_…" }
    }
  }
}
```

## Or let the kosa8 CLI do it

Signed in with `kosa8 cloud login`, the CLI prints every snippet above for your key, and writes them only when you ask:

```
$ kosa8 cloud mcp                        # print the config for each client; writes nothing
$ kosa8 cloud mcp cursor --show-key      # Cursor's, with the key itself in it
$ kosa8 cloud mcp --install claude-code  # or cursor, codex; none named: every one found
$ kosa8 cloud mcp --uninstall cursor
```

`--install` keeps the client's other servers and saves the old file as `.bak`. Cursor's file gets the key and is made readable only by you; Codex's gets only the variable name. The server is named `kosa8-cloud`, so it sits beside the local `kosa8` server from `kosa8 mcp install` ([Connect Claude, Cursor or Codex](https://docs.kosa8.com/guides/connect-agents/)), which runs sandboxes on your own machine.

## Tools

| Tool | Does | Scope |
|---|---|---|
| `sandbox_create` | Start a sandbox. All optional: `template`, `region`, `size` (`0.25x0.5`, `0.5x1`, `1x2`, `2x4`, `4x8`, `8x16`, `16x32`; the three small ones reserve part of a vCPU and burst when the host is idle) or `cpus` + `mem_mb`, `image` (e.g. `kosa8-template/universal-24.04-20261115.2`), `docker`, `kvm` (preview: `/dev/kvm` for an emulator), `disk_gb`, `persistent`, `cpu: dedicated`, `env`, `labels`, `name`, `snapshot`, `sleep_after_s`, `ttl_s`, `repo` (`"owner/name@ref"`: a repo of the connected GitHub, cloned into `/workspace/<name>`; see [GitHub repos](https://docs.kosa8.com/guides/cloud-github/)). A sized, image or docker sandbox may come back `creating`: poll `sandbox_get`. | `sandboxes:write` |
| `sandbox_get` | One sandbox: state, size, image, labels, cost so far. | `sandboxes:read` |
| `sandbox_list` | The organization's sandboxes, their state and cost so far. | `sandboxes:read` |
| `sandbox_exec` | Run `argv` (exact arguments) or `command` (a shell line, run with `sh -c`), with optional `env`. Returns the exit code, stdout and stderr. A sleeping sandbox wakes first; `/workspace` persists between commands. A command runs at most 90 seconds (set `timeout_s` to stop it sooner); for longer work set `background: true`, which returns an exec id (`bg_…`) at once. | `sandboxes:write` |
| `sandbox_exec_status` | A background command's state, exit code and output so far. | `sandboxes:read` |
| `sandbox_exec_stop` | End a background command and what it started: SIGTERM, then SIGKILL after 5 seconds. | `sandboxes:write` |
| `sandbox_sleep` | Snapshot it and free its RAM; it then costs only snapshot storage. | `sandboxes:write` |
| `sandbox_wake` | Restore a sleeping sandbox now. | `sandboxes:write` |
| `sandbox_delete` | Delete it and everything in it. | `sandboxes:write` |
| `sandbox_logs`, `sandbox_metrics` | Its last commands with exit codes and output tails; its CPU, memory, disk and network use. | `sandboxes:read` |
| `file_read`, `file_list` | Read a file (text as text up to 8 MiB; other bytes as base64 up to 100 KB, larger ones through `file_link`); list a folder. | `sandboxes:read` |
| `file_write`, `file_mkdir`, `file_delete` | Write text or base64 bytes to a file; make a folder; remove a file or, with `recursive`, a folder. | `sandboxes:write` |
| `file_link` | A presigned one-time URL to download (GET) or upload (PUT) one path with no size cap. An upload link needs a write key. | `sandboxes:read` |
| `code_run` | Run Python in a stateful kernel (`context` names one); stdout, the cell's value, and matplotlib charts as image content. Needs a persistent sandbox. | `sandboxes:write` |
| `preview_create`, `preview_link`, `preview_delete` | Give a port its own https URL (private signed link unless `public`), make a new link, close it. | `sandboxes:write` |
| `preview_list` | The sandbox's preview URLs, without tokens. | `sandboxes:read` |
| `snapshot_create`, `snapshot_delete` | Save a sandbox (memory, processes, disk) as an org snapshot kept until deleted; delete one. Start from one with `sandbox_create` `snapshot`. | `sandboxes:write` |
| `snapshot_list` | The organization's snapshots, optionally one sandbox's. | `sandboxes:read` |
| `checkpoint_create`, `sandbox_rewind`, `sandbox_fork` | Checkpoint `/workspace`, rewind to a checkpoint, make `n` copies of a sandbox. | `sandboxes:write` |
| `checkpoint_list` | A sandbox's checkpoints. | `sandboxes:read` |
| `sandbox_batch_create`, `sandbox_drain` | Create 1 to 1000 sandboxes at once from one template or image (tag them with `run_id`); delete every sandbox with a `run_id`, labels or ids. | `sandboxes:write` |
| `sandbox_grade` | Fork a solved sandbox with no network, write hidden test files into the copy, run the grader and return a reward, then delete the copy. | `sandboxes:write` |
| `pipeline_run`, `pipeline_cancel` | Run a repository's `.kosa8/pipeline.yml` (or `.github/workflows` through act); cancel a run. Secrets are passed by name only. | `sandboxes:write` |
| `pipeline_list`, `pipeline_get`, `pipeline_logs` | Runs, one run's jobs, and its logs by job (secrets shown as `***`; `after` for only new lines). | `sandboxes:read` |
| `browser_open`, `browser_goto`, `browser_screenshot`, `browser_close` | Open a headless Chromium (its `cdp_url` works with Playwright's `connectOverCDP`), open a URL and get its title and text or a PNG screenshot, close it. An open browser counts toward usage until it is closed or reaches `ttl_s` (300 by default). | `sandboxes:write` |
| `browser_list` | The organization's open browsers and how many may be open at once. | `sandboxes:read` |
| `github_repos` | The connected GitHub repos the organization can use, most recently pushed first; `query` searches by name. | `sandboxes:read` |
| `open_pull_request` | Commit what changed in a sandbox's repo, push a branch and open a draft pull request (`sandbox_id`, optional `title` and `body`); returns its link. The GitHub token never enters the sandbox. | `sandboxes:write` |
| `github_status` | Whether GitHub is connected, which accounts, and any missing App permissions; `connect_url` when it is not connected (the person opens it). | `sandboxes:read` |
| `github_branches` | A connected repo's branches (`repo`: owner/name) and its default branch. | `sandboxes:write` |
| `run` | One call: a fresh sandbox runs a `command` (or `code`) and is removed. With `repo`, a connected repo is cloned first and the command runs in it; `github_check` puts the result on that commit as a check run. | `sandboxes:write` |
| `pipeline_connect` | Run a connected repo's pipeline on every push and pull request through the kosa8 GitHub App (`repo`, optional `events`): no webhook or token. | `admin` |
| `ci_jobs` | GitHub Actions jobs that ran on kosa8 runners, newest first, with minutes, cost and this month's CI minutes. | `sandboxes:read` |
| `usage_get` | This month's bill so far, the spending cap, and whether new work is paused. | `sandboxes:read` |
| `templates_list` | The templates you can create now. | `sandboxes:read` |

The agent sees only the tools its key's scopes allow: a `sandboxes:read` key gets the read tools. No tool sets a secret or changes egress: secrets are stored by a person (`kosa8 cloud secrets set`, value from stdin, or the dashboard) and an agent only names them. Output longer than 100 KB per stream is cut, with a note saying how much.

## Hand one sandbox to someone else: capability tokens

A platform that gives its own users a sandbox (a browser terminal, a student's notebook, a customer's agent) should not hand them its API key. Make a short-lived token instead, limited to the scopes and sandboxes that user needs, and give them that. It works on the REST API and at `/mcp`:

```
curl -s https://api.kosa8.com/v1/tokens -H "Authorization: Bearer $KOSA8_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{"scopes":["sandboxes:write"],"sandbox_ids":["sbx_…"],"ttl_s":3600,"name":"student 42"}'
```

- The answer holds `token.secret` (`k8c_tok_…`) once; kosa8 keeps only its hash. `ttl_s` is at most 86400 (24 hours), one hour by default.

- `scopes` come from `sandboxes:read`, `sandboxes:write` and `functions:invoke`, and only ones the key making it holds. A token limited to some sandboxes or labels holds sandbox scopes only.

- `sandbox_ids`: the token reaches only those sandboxes. Any other is `404 not_found`, as another organization's is.

- `labels` (for example `{"user":"u42"}`): the token reaches only sandboxes with every one of those labels, and a sandbox it creates gets them, so a user can make their own sandboxes and see only those.

- A token limited either way can use one sandbox's routes, the sandbox list (filtered) and the template list. Everything else answers `403 token_restricted`: settings, billing, keys, members, secrets, snapshots, swarms, pipelines, other sandboxes. It cannot fork, relabel, change egress, give a sandbox the organization's secrets or start one from a snapshot.

- It is never worth more than what made it: revoking the key that made it, removing the member, or freezing the organization stops it. A token cannot make tokens or keys.

- The dashboard's **Keys & secrets, Capability tokens** page makes them (scopes, sandboxes, labels, lifetime), shows the secret once with a copy button, and lists and revokes them. The E2B-compatible API (`/e2b`) takes them too, with the same limits; an OAuth access token works only at `/mcp` and is refused there.

- `GET /v1/tokens` lists them (never a secret), `DELETE /v1/tokens/{id}` revokes one at once. Making and revoking are audited (`token.create`, `token.revoke`), and every call made with one is recorded as `token:{id}`.

## Same rules as the API

Each tool runs the same code as its REST call, so everything that applies to the API applies here: the key's scopes, payment, your spending cap, the sandbox quota, and the audit log. Each call appears in **Audit** with `via: mcp`; an exec records its arguments, the names of its environment variables and its exit code, never its output or variable values.

When kosa8 Cloud refuses something, the agent gets a tool error it can read, not a broken connection. A **402** (`payment_required` or `spending_cap_reached`) includes a sentence meant for you and the page that fixes it, for example:

```
kosa8 Cloud refused this (HTTP 402 payment_required): add a payment method to start running work; …
Tell the person: kosa8 Cloud needs a payment method to run more work. Ask the person to open https://app.kosa8.com/#usage
upgrade_url: https://app.kosa8.com/#usage
```

The server tells agents to pass that on and stop, rather than retry.

## Details

- Stateless: each `POST /mcp` carries one JSON-RPC 2.0 message (or a batch) and is answered with `application/json`. There is no session id and no event stream, so `GET` and `DELETE` return 405.

- Only a bearer token is accepted (an OAuth access token, an API key or a capability token), never the dashboard's sign-in cookie. A missing, expired or revoked one is HTTP 401 with a `WWW-Authenticate` header naming the protected resource metadata.

Try it by hand:

```
curl -s https://api.kosa8.com/mcp -H "Authorization: Bearer $KOSA8_API_KEY" \
  -H 'Content-Type: application/json' -H 'Accept: application/json, text/event-stream' \
  -d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'
```

---
Source: https://docs.kosa8.com/guides/cloud-mcp/
