# How kosa8 works

kosa8 is three programs and a boundary. A command-line tool you type into, a background service that does the work, and a small helper inside every virtual machine. Everything an AI assistant does happens on the far side of the boundary; everything that decides what it may do stays on yours.

## The whole thing in one picture

> Diagram: On your computer: the kosa8 command and an AI client talk to the kosa8d service over a private socket. kosa8d holds the policy, the audit log and the network guard. Each sandbox is a separate virtual machine with its own kernel, reached only through a control channel and a filtered network.

What runs where. The dashed lines are trust boundaries; the moving lines are the only ways across them.

1. You type a command, or an AI client calls a tool. Both arrive at the same place.

2. `kosa8d`, a service running as your user, receives it over a socket only you can open.

3. Before anything happens it is checked against policy, attributed to whoever asked, and written to the audit log.

4. The work itself runs in a sandbox: a real virtual machine with its own kernel. Nothing in it can see your files except the one folder you shared.

5. Every packet the machine sends passes the network guard, which lives on your side where nothing inside the machine can reach it.

6. API keys stay with the broker. The assistant gets a stand-in that is worthless anywhere else.

7. Requests to the hosts you named go out, with the real key added on the way.

8. Anything else is refused before it leaves your computer, and the attempt is recorded.

## The three programs

**kosa8**The command-line tool. It holds no state and does no work of its own: every command is a request to the service. That is why the Mac app, the CLI and an AI client always agree about what is running — they are all asking the same thing.

**kosa8d**The background service. It starts and stops virtual machines, enforces policy, runs each sandbox's network, and is the only writer of the audit log. It runs as you, without administrator rights.

**kosa8-guestd**A small helper inside each virtual machine. It starts containers when the service asks. It is on the untrusted side: nothing the service decides depends on it telling the truth.

## Two kinds of place to run things

kosa8 can run a container in two places, and the difference matters.

### The shared engine

`kosa8 run` and the Docker-compatible API use one always-warm virtual machine for all your everyday containers. It starts in milliseconds and behaves like Docker. Containers in it are separated from your Mac by a VM, and from each other by ordinary container isolation.

### A sandbox

`kosa8 sandbox` and `kosa8 agent run` give the work a virtual machine of its own: its own kernel, its own disk, its own private network with its own rules. This is where an AI assistant belongs, and where save, copy and undo work.

**Want everything in a sandbox?**

An organisation can require it. With `require_sandbox` in the signed policy, the shared engine refuses to run anything and every container gets a machine of its own. See [Policy reference](https://docs.kosa8.com/guides/policy-reference/).

## What crosses the boundary

A sandbox is useful only if the list of things that cross into and out of it is short. This is the whole list.

| Crossing | Direction | Who controls it |
|---|---|---|
| Control channel | Your side → sandbox | The service only. It is not a network connection, and the sandbox cannot open one back. |
| Shared folder | Both | You, when you create the sandbox. Exactly the folders you named; writable unless you add `:ro`. |
| Network | Sandbox → world | The network guard, by the sandbox's rules. See [Network rules](https://docs.kosa8.com/guides/network/). |
| Credentials | Never | They stay with the broker. See [Keep API keys out of the sandbox](https://docs.kosa8.com/guides/credentials/). |
| Disk and memory | Neither | Each sandbox has its own. A snapshot is a file on your side that the sandbox cannot read. |

## What happens when you create a sandbox

> Diagram: Five steps left to right: check policy, clone the disk, start the network, boot the virtual machine, ready.

The network and its rules exist before the machine boots, so there is no moment in which a sandbox is running without them.

```
$ kosa8 sandbox create dev --egress-allow registry.npmjs.org
sandbox dev ready in 737ms (32 GB disk)
$ kosa8 sandbox pull dev alpine
$ kosa8 sandbox run dev alpine uname -r
6.18.35
$ kosa8 sandbox egress dev
policy:   allow:registry.npmjs.org (enforced on the host)
frames:   3 passed, 0 denied, 1 dropped as link noise
dns:      2 answered, 0 refused
```

## Where things are kept

All of kosa8's state is in one folder in your home directory, `~/.kosa8`, readable only by you.

| Path | What it is |
|---|---|
| `run/kosa8.sock` | The socket the command talks to the service over. |
| `sandboxes/` | Each sandbox's disks and record. |
| `snapshots/` | Saved machines. |
| `audit.jsonl`, `audit.key` | The audit log and the key that makes it tamper-evident. |
| `policy.json`, `mcp-policy.json` | Your organisation's signed rules, if it has any. |
| `agents.json` | Agent identities. Tokens are stored as digests, never as themselves. |
| `mcp-servers.json`, `mcp-pins.json` | Third-party tool servers and the definitions they are pinned to. |
| `kits/` | Your own sandbox kits. |
| `log/` | The service's log and each sandbox's console. |

## Where to go next

[`Securing an agent` The layers between an AI assistant and the things it could damage.](https://docs.kosa8.com/guides/secure-agents/) [`Network rules` What a sandbox can reach, and where that is enforced.](https://docs.kosa8.com/guides/network/) [`The audit log` What is written down, and how to prove nobody edited it.](https://docs.kosa8.com/guides/audit/) [`For developers` The source layout, the API, and how to build and test.](https://docs.kosa8.com/guides/developers/)

---
Source: https://docs.kosa8.com/guides/how-it-works/
