# Bring your own cloud (next release)

Join your own servers to your kosa8 Cloud organization. Your sandboxes and functions then run as microVMs on hardware you control, in your network and region, through the same API, SDKs, MCP server and dashboard. kosa8 keeps placing, signing and metering them. Only your organization's work runs on your hosts, and kosa8 charges a flat fee per host-hour on them instead of compute.

## Install

**Managed tunnels are coming soon. [Contact us](mailto:contact@kosa8.com)** if you want one. Today each host needs an `https://` address of its own that reaches `127.0.0.1:7441` on it: a tunnel or reverse proxy you run, such as cloudflared on your own Cloudflare account. Set it up first ([Bring your own tunnel]) and pass it as `KOSA8_URL`. Without `KOSA8_URL` the script stops before it changes anything.

In the dashboard, open **Own hosts** and make a **registration token** (it starts `k8r_` and is shown once). Then, on a fresh Ubuntu 24.04 machine with KVM:

```
curl -fsSL https://kosa8.com/byoc.sh | sudo KOSA8_REG_TOKEN=k8r_… KOSA8_URL=https://kosa8-rack1.example.com sh
```

The script:

1. Checks the machine and stops with a fix for each problem it finds: no `/dev/kvm` (with the steps for AWS, Google Cloud, Azure and other platforms), too little memory, no XFS, blocked network.

2. Installs a few Ubuntu packages, and puts kosa8's data on XFS with reflink at `/var/kosa8`. That can be a spare disk (`KOSA8_DATA_DEV=/dev/nvme1n1 KOSA8_FORMAT_DATA=yes`, which erases it). Without one, the script makes a sparse XFS image file. Fork clones disks by reflink, so ext4 is not enough.

3. Downloads the kosa8 release (`kosa8d`, `k8agent`, the CLI), Cloud Hypervisor, and checks each one before it runs anything. The release is checked against its `checksums.txt`, and the signature on that file is verified too when the release carries one and `cosign` is installed. Cloud Hypervisor is checked against a SHA-256 digest pinned in the script.

4. Installs systemd units for `kosa8d` and `k8agent`, registers the host at your `KOSA8_URL`, and waits until it shows up under Own hosts.

To see what it would do first:

```
curl -fsSL https://kosa8.com/byoc.sh | sh -s check                        # preflight only; changes nothing
curl -fsSL https://kosa8.com/byoc.sh | sudo KOSA8_REG_TOKEN=k8r_… KOSA8_URL=https://… sh -s dry-run   # also downloads and verifies, then prints every step
```

Running it again is safe. It repairs what is missing, upgrades to the pinned release, saves every sandbox before it restarts `kosa8d`, and never registers the host twice.

| Option | Default | What it does |
|---|---|---|
| `KOSA8_REG_TOKEN` | (required the first time) | The `k8r_` token from Own hosts. One token can register several hosts until it expires (at most 30 days). The host deletes it once it has its own credential. |
| `KOSA8_REGION` | the cloud region from instance metadata (AWS, GCP, Azure), else `on-prem1` | Your name for where the host is. Sandboxes created with `"region": "…"` go to hosts there. |
| `KOSA8_URL` | (required today) | Your own tunnel or proxy: the `https://` address that reaches `127.0.0.1:7441` on this host. |
| `KOSA8_MANAGED_TUNNEL` | off | `1` asks kosa8 to make the host's tunnel instead of `KOSA8_URL`. Coming soon: [contact us](mailto:contact@kosa8.com) before using it. |
| `KOSA8_DATA_DEV`, `KOSA8_FORMAT_DATA` | none | A whole disk for `/var/kosa8`. `KOSA8_FORMAT_DATA=yes` formats it XFS (erasing it). |
| `KOSA8_LOOP_GB` | free space less 20 GB, at most 500 | The size of the XFS image file when there is no XFS and no disk. `0` refuses the image file. |
| `KOSA8_VERSION` | the release the script pins | Install another release (`vX.Y.Z`, or `latest`). |
| `KOSA8_TEMPLATES` | base, python, node | A templates file: `[{key, image, cpus, mem_mb, depth}]`. Each template keeps a warm pool. |
| `KOSA8_POOL_PCT` | `15` | The share of RAM the warm pools may hold. |

### Requirements

- **KVM.** Each sandbox is a microVM, so the machine needs bare metal or a VM with nested virtualization. On AWS that means a bare-metal instance type (`*.metal`), or an instance type AWS documents as supporting nested virtualization. On Google Cloud, create the VM with `--enable-nested-virtualization` on an Intel machine type. On Azure, use a size that supports nested virtualization (for example Dsv5 or Dsv6; Confidential VM sizes do not). Hetzner Cloud and DigitalOcean VMs have no KVM, so use their dedicated servers or another provider. `check` tells you which of these applies to your machine.

- **x86-64, Ubuntu 24.04 LTS** (26.04 also works), systemd, 8 GB of RAM or more (32 GB or more for real work).

- **XFS with reflink, or btrfs, at `/var/kosa8`**. A spare NVMe disk is best. The image file works, but costs some disk speed.

## What stays in your environment, and what kosa8 sees

| Stays on your host | kosa8's control plane sees |
|---|---|
| The sandboxes themselves: their memory, disks and processes Code and data you put in them, and what they write Snapshots, checkpoints and sleeping sandboxes (in `/var/kosa8`) Template images, pulled by the host from their registries Traffic between sandboxes and your network | Metadata: sandbox ids, templates, sizes, states, timestamps, labels Metering: when each sandbox runs and sleeps, and when each host is registered Host health from heartbeats every 5 s: cores, memory, pool depth, version The audit log: what ran and its exit code, never its output |

Two kinds of traffic pass through kosa8 in transit, without being stored:

- Commands, files and streams you send through `api.kosa8.com` go from the control plane to your host. To keep them off it, use the direct URLs the API returns (`exec_url`, `files_url`), which go to your host through its tunnel.

- TLS on that path ends wherever your `KOSA8_URL` ends it: at Cloudflare's edge for a cloudflared tunnel, or on your own network for a reverse proxy you run.

Features that keep data with kosa8 by design say so in their own guides. For example, desktop session recordings are stored by kosa8 when you turn recording on.

## Network

Everything is outbound. The host opens no inbound port: `k8agent` listens on `127.0.0.1:7441` only, and kosa8 reaches it through your tunnel (cloudflared dials out), or through a reverse proxy you choose to expose.

| To | Port | Why |
|---|---|---|
| `api.kosa8.com` | 443 | Registration and heartbeats |
| `region1.v2.argotunnel.com`, `region2.v2.argotunnel.com` | 7844, TCP and UDP | Only if your tunnel is cloudflared |
| `github.com`, `objects.githubusercontent.com`, `release-assets.githubusercontent.com` | 443 | Install and upgrade, and the guest image on first start |
| Your template images' registries (Docker Hub by default) | 443 | Template images |
| Whatever your sandboxes reach |  | Set per sandbox or per organization: [Egress controls](https://docs.kosa8.com/guides/cloud-egress/) |

`HTTPS_PROXY` is honoured for the control-plane calls.

### Bring your own tunnel

This is the path that works today. Give the host an `https://` hostname that reaches `127.0.0.1:7441` on it, then pass that hostname as `KOSA8_URL`. With cloudflared on your own Cloudflare account (free plan is fine, the host opens no inbound port):

1. In the Cloudflare dashboard, open **Zero Trust → Networks → Tunnels** and create a tunnel (type cloudflared), for example `kosa8-rack1`.

2. Install the connector on the host with the command Cloudflare shows (`sudo cloudflared service install <token>`).

3. Add a public hostname, for example `kosa8-rack1.example.com` on a zone of yours, with service `http://127.0.0.1:7441`.

Any other TLS tunnel or reverse proxy (nginx, Caddy, a load balancer) works the same way, and ends TLS on your side. Then install:

```
curl -fsSL https://kosa8.com/byoc.sh | sudo KOSA8_REG_TOKEN=k8r_… KOSA8_URL=https://kosa8-rack1.example.com sh
```

**Managed tunnels, coming soon.** kosa8 will be able to make each host a Cloudflare tunnel on kosa8's account, so you need no Cloudflare account and no hostname of your own. It is not switched on yet; [contact us](mailto:contact@kosa8.com) if you need it.

## Pricing

Sandboxes and functions on your own hosts carry no compute charge. Each registered host is billed per host-hour while it is registered, at the rate on [the pricing page](https://kosa8.com/pricing/) (also `rates.byoc_host_h` from `GET https://api.kosa8.com/v1/pricing`, which needs no key). Your organization needs a kosa8 Cloud plan. Removing a host stops its fee.

## Operate it

| What | Where |
|---|---|
| Service logs | `journalctl -u kosa8d -u k8agent` (and `-u cloudflared` for a cloudflared tunnel) |
| The installer's log | `/var/log/kosa8/byoc.log` |
| Binaries | `/opt/kosa8-byoc/current` (the previous release is kept beside it) |
| Data, snapshots, the host's state | `/var/kosa8` (`k8agent/state.json`, mode 0600, holds the host's credential) |
| Settings | `/etc/kosa8-byoc/byoc.env` (no secrets) |
| Upgrade | Run the install line again. It drains first, so sandboxes are saved, not stopped. |
| Health | `curl -s http://127.0.0.1:7441/host/v1/health` on the host. The dashboard shows each host's last heartbeat. |

### Remove a host

```
curl -fsSL https://kosa8.com/byoc.sh | sudo sh -s uninstall                 # leaves the org, removes services and binaries
curl -fsSL https://kosa8.com/byoc.sh | sudo KOSA8_PURGE=1 sh -s uninstall   # also deletes /var/kosa8: sandboxes, snapshots, the image file
```

Uninstall takes the host out of your organization first: its credential stops working and its fee stops. A tunnel or proxy you made yourself stays; remove it on your side. **Own hosts → Remove** in the dashboard does the same from the other side. The sandboxes still on the host are marked `host_removed`.

## Kubernetes

**Coming soon, [contact us](mailto:contact@kosa8.com).** The DaemonSet is meant for managed tunnels, which give every node its own address. Until they are on, each node needs its own `KOSA8_URL`, so the manifest suits one labelled node.

A DaemonSet runs one kosa8 host on each node you label. On each node, the pod runs `byoc.sh container`: `kosa8d` and `k8agent` in the foreground, with binaries and state cached in the node's `/var/kosa8`, so a restarted pod keeps its registration.

```
kubectl create namespace kosa8
kubectl -n kosa8 create secret generic kosa8-byoc --from-literal=reg-token=k8r_…
kubectl label node NODE kosa8.com/byoc=true
curl -fsSLO https://kosa8.com/byoc-kubernetes.yaml   # set KOSA8_URL in it first
kubectl apply -f byoc-kubernetes.yaml
```

Download the manifest first and edit it: set `KOSA8_URL` (required today) and `KOSA8_REGION`, and pin `KOSA8_VERSION` if you like.

What this needs, honestly:

- **KVM on the nodes.** The same requirement as above, which rules out most default node pools. On EKS, use bare-metal instance types. On GKE Standard, use node pools with nested virtualization on Intel machine types (not Autopilot). On AKS, use node sizes that support nested virtualization. On premises, any node with VT-x or AMD-V works.

- **Privileged pods.** `kosa8d` needs `/dev/kvm` and tap devices. The manifest labels its namespace for the `privileged` Pod Security level, and admission policies such as Gatekeeper or Kyverno must allow it.

- **XFS at `/var/kosa8` on each node**, prepared before the pod starts (a local NVMe formatted with `mkfs.xfs -m reflink=1`, from the node's startup script or image). The pod checks this and says what is missing.

- **One host per node.** Sandboxes use the node's memory directly, so keep other workloads off these nodes (taint them `kosa8.com/byoc=true:NoSchedule`, which the DaemonSet tolerates). Cluster autoscaling does not see sandbox load.

- Pods usually cannot reach the cloud's metadata service, so set `KOSA8_REGION`.

Deleting a pod drains its host first (a `preStop` hook), so its sandboxes are saved. A node that leaves the cluster stays under Own hosts until you remove it there. The Kubernetes form is a preview: tell us about your cluster and we will help you set it up.

## Troubleshooting

- **"no hardware virtualization"**: see [Requirements]. `check` names your platform and what to change.

- **"refused the registration token"**: the token expired, was revoked or was mistyped. Make a new one under Own hosts.

- **"KOSA8_URL is not set"** or **"could not make this host's tunnel"**: managed tunnels are not on yet. Bring your own tunnel with `KOSA8_URL` ([how]).

- **"was not installed by this script"**: the machine already runs kosa8 another way. The script leaves it alone unless you set `KOSA8_FORCE=1`.

- **The host shows as down**: `journalctl -u k8agent -n 50`, and check that your `KOSA8_URL` still reaches `127.0.0.1:7441`.

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