# Swarms

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

## The organization's swarms, newest first, without counters[#]

GET`/v1/swarms`scope sandboxes:read

Responses

200401403

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

## Checkpoint a sandbox and fork it into a named swarm under one egress policy[#]

POST`/v1/swarms`scope sandboxes:write

The checkpoint and the fork are the same calls as POST /v1/sandboxes/{id}/checkpoints and /fork, with the same payment, quota and fork limits. Members are labelled swarm, swarm.member and swarm.parent. If a member's egress policy cannot be applied, every member is deleted (502 egress_failed).

JSON body

`name`requiredstring

—

`from_sandbox_id`requiredstring

A running or sleeping sandbox

`count`requiredinteger

Min 1. Max 100.

`egress`object

The members' egress policy. Default: the parent's own, else the organization's

`egress.internet`boolean

false: nothing leaves but what allow and presets name. Default true when nothing is listed

`egress.allow`array of string

Hostnames (exact), *.domain wildcards (any depth below, not the domain), IPv4 addresses or CIDRs

`egress.deny`array of string

Refused even where allow covers them. A name is refused at DNS; a CIDR for every packet

`egress.presets`array of "common" | "npm" | "pypi" | "github" | "go" | "crates" | "rubygems" | "maven" …

—

Responses

201400401402403404409429501502503

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

## A swarm with each running member's egress counters and anomalies[#]

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

?stats=0 skips the counters. Counters come from the host: packets refused by egress and bytes out since the member last booted. Anomalies found (denied_burst: >= 20 refused; egress_spike: bytes out > 10x the median and > 1 MiB) are kept and written once to the audit log as swarm.anomaly. rare_host needs the hosts each member contacted, which kosa8 Cloud hosts do not report.

Parameters

`id`requiredpath · string

Swarm id (swm_…) or name

Responses

200401403404

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

## Put every running member to sleep (state kept)[#]

POST`/v1/swarms/{id}/pause`scope sandboxes:write

Parameters

`id`requiredpath · string

Swarm id (swm_…) or name

Responses

200401403404

```
curl -s -X POST https://api.kosa8.com/v1/swarms/$SBX/pause \
  -H "Authorization: Bearer $KOSA8_API_KEY"
```

## Wake every sleeping member[#]

POST`/v1/swarms/{id}/resume`scope sandboxes:write

Parameters

`id`requiredpath · string

Swarm id (swm_…) or name

Responses

200401403404409

```
curl -s -X POST https://api.kosa8.com/v1/swarms/$SBX/resume \
  -H "Authorization: Bearer $KOSA8_API_KEY"
```

## The kill switch: every running member to sleep and the swarm marked killed[#]

POST`/v1/swarms/{id}/kill`scope sandboxes:write

Works while the organization is frozen. A killed swarm's name can be used again.

Parameters

`id`requiredpath · string

Swarm id (swm_…) or name

`rm`query · "1"

1: delete every member instead

Responses

200401403404

```
curl -s -X POST https://api.kosa8.com/v1/swarms/$SBX/kill \
  -H "Authorization: Bearer $KOSA8_API_KEY"
```

---
Source: https://docs.kosa8.com/api/swarms/
