MAQPNADocs

kosa8 reference

Every MAQPNA setting, flag, policy field, ledger rule, kosa8d API call, environment variable, path, metric and error of the kosa8 integration, read from the source.

This page lists everything MAQPNA reads, writes and calls for kosa8, the microVM container platform from Kosa8 Labs. For the steps, see Run MAQPNA sessions in kosa8 sandboxes. The source is pkg/kosa8 (client), pkg/sandbox/kosa8sandbox (sandbox driver), cmd/maqpna-gateway/kosa8.go (decision mirror and audit anchor) and cmd/maqpna/dev_sandbox.go (maqpna dev commands).

flowchart LR
    CLI["maqpna dev<br/>run, fork, snapshot,<br/>restore, attest"] -->|"sandbox driver"| K["kosa8d"]
    BR["Identity broker<br/>-sandbox-check kosa8"] -->|"read sandbox, egress, inventory"| K
    GW["Gateway<br/>kosa8 block"] -->|"POST /kosa8/v1/ai/records"| K
    GW -->|"GET /kosa8/v1/audit/verify, /audit?limit=1"| K

Gateway config: kosa8#

The kosa8 block of gateway.json turns on the decision mirror and the audit anchor. It is off unless mirrorDecisions is true or anchorIntervalSeconds is above 0.

Field Type Default Description
socket string ~/.kosa8/run/kosa8.sock when url is empty kosa8d's unix socket.
url string — A kosa8d serving TCP (kosa8 daemon start --listen ADDR). http:// is accepted only to a loopback host (localhost, 127.0.0.1, ::1); use https:// for any other host. No user info in the URL.
tokenFile string — File with kosa8d's bearer token. Required with url.
mirrorDecisions bool false Post each tool-call decision of the ledger to kosa8's audit chain as an mcp.decision record. Model calls (llm/* servers) are not mirrored.
anchorIntervalSeconds int 0 (off) Read and anchor kosa8's audit head in the ledger this often.
queueSize int 1024 Decisions waiting to be mirrored. Past it, decisions are dropped and counted.

Validation errors (the gateway refuses to start; maqpna-gateway -check-config reports them):

Error Cause
kosa8.url: invalid URL "…" Not http or https, no host, or user info in the URL.
kosa8.url: "…" is plain HTTP to a non-loopback host; put kosa8d behind TLS (https://) The token is a full kosa8d credential and is never sent in clear over a network.
kosa8.tokenFile is required with kosa8.url (kosa8d refuses TCP without a token) url set without tokenFile.
kosa8: set socket or url, not both Both set.
kosa8: anchorIntervalSeconds and queueSize must be >= 0 A negative value.
kosa8.tokenFile: … The token file cannot be read.

maqpna dev up --kosa8 writes "kosa8": {"mirrorDecisions": true, "anchorIntervalSeconds": 30}. To change it, pass --gateway-config FILE with a kosa8 object: top-level keys of that file replace the generated ones. A full example is in the MAQPNA source, examples/integrations/gateway-llamay-kosa8.json.

Helm values#

The chart has no kosa8 values. kosa8d is a per-user daemon on a workstation or edge host, not a cluster service, so the integration is built for maqpna dev. gateway.config is rendered into the gateway's gateway.json as is, so a gateway.config.kosa8 block reaches a gateway in a cluster:

gateway:
  config:
    kosa8:
      url: https://kosa8-worker.example.eu
      tokenFile: /mnt/secrets-store/kosa8-token
      anchorIntervalSeconds: 60
  secretsStoreCSI:
    enabled: true
    secretProviderClass: maqpna-kosa8-token

This is not a tested setup: no kosa8 sandbox runs in the cluster, and the operator does not use the kosa8 driver. See MAQPNA on Kubernetes and Helm values.

maqpna dev flags#

Command Flag Default Description
dev up --kosa8 false Check kosa8d health, serve the gateway on the LAN address, start the broker with the kosa8 check, write the kosa8 gateway block.
dev up --kosa8-host-ip IP LAN address of the default route The host IPv4 address sandboxes dial. Must not be loopback.
dev run --kosa8-image IMAGE — Run the command in this OCI image in a kosa8 microVM. Needs dev up --kosa8 and /bin/sh in the image.
dev run --kosa8-cpus N kosa8's default vCPUs.
dev run --kosa8-mem-mb N kosa8's default Memory in MiB.
dev run --kosa8-keep false Keep the sandbox after the command exits. Without it, the sandbox is removed with its disks wiped.
dev fork, snapshot, restore, attest --sandbox NAME kosa8 Sandbox driver: agent-sandbox, e2b or kosa8.
dev fork --session S, --name STEM, --attach, --ttl last session, <session>-fork, true, 1h The child session is <stem>-1.
dev snapshot --session S, --id ID last session, <session>-<UTC time> Checkpoint id: [A-Za-z0-9._-], 1 to 80 characters.
dev restore --checkpoint ID, --name STEM, --attach, --ttl required, <session>-restore, true, 1h The new session is <stem>-1.
dev attest --session S last session Exit status 3 when the egress is not exactly the gateway.

Full flag lists: maqpna dev up, dev run, dev fork, dev snapshot, dev restore, dev attest.

Sandbox driver: kosa8#

Property Value
Driver name kosa8
Isolation microvm
Egress allow:<gateway IPv4>, enforced by kosa8 (egressEnforced: true). The gateway must be a non-loopback IPv4 literal.
Live fork yes
Snapshot and restore yes
Attestation inventory (kernel, rootfs and image digests the host reports); none when kosa8 returns no digest
copyResumesBeforeRekey true: a fork or restore runs with its source's token until it is re-keyed
Sandbox name maqpna-<session>, characters outside [A-Za-z0-9._-] replaced with -, at most 63 characters
Daemon $KOSA8_HOST and $KOSA8_TOKEN, else ~/.kosa8/run/kosa8.sock

Sandbox labels (the broker check reads them; a copy keeps its source's labels):

Label Value
maqpna.com/session Session id
maqpna.com/namespace Namespace
maqpna.com/agent Agent
maqpna.com/user On-behalf-of user
maqpna.com/scopes Scopes, comma-separated
maqpna.com/parent-session Parent session, for a copy

Token delivery inside the sandbox:

Item Value
Token file /tmp/maqpna/token, mode 0600
Boot /bin/sh -c '<boot shell>' maqpna CMD...: reads one line from stdin into the token file, then execs the command. An empty stdin starts no command.
Delivery POST …/containers/{cid}/stdin. Not in argv, not in the environment.
Re-key (fork, restore) exec /bin/sh -c '<rotate shell>' maqpna <token>: writes token.new and renames it over the token file. A copy that cannot be re-keyed is removed.

Identity broker flags#

maqpna dev up --kosa8 passes the first two. Use them on your own maqpna-identity:

Flag Default Description
-sandbox-check kosa8 — Verify mint proofs for sessions in kosa8 sandboxes. The broker asks kosa8d, never the caller.
-sandbox-check-gateway URL — Required with -sandbox-check: the gateway URL the sandbox's egress must be pinned to.
-sandbox-check-min-isolation microvm Weakest isolation accepted.
-sandbox-check-min-attestation inventory none, inventory or measured.
-sandbox-check-allowed FILE — JSON map of measurement name to accepted SHA-256 digests: kernel, rootfs, image:<ref>. An unlisted name is accepted as reported.
-require-proof false Refuse every POST /v1/token without a verified proof.

The broker refuses a mint (403, error identity: proof refused: …) when:

  • the proof names no sandbox, or kosa8d does not list it;
  • the sandbox's labels name another namespace, agent or user, or another session (a copy passes when kosa8 reports a parent and the labelled session is the request's parent session or fork root);
  • the egress kosa8 enforces now is not exactly the gateway;
  • isolation or attestation is below the floor;
  • a measurement is not in -sandbox-check-allowed.

On success the token carries maqpna_substrate: check (kosa8), sandbox, isolation, attestation, egress, digest (SHA-256 over the sorted name=sha256 measurements) and platform (for example kosa8 0.9.36 f6124c0).

ToolPolicy substrate fields#

A rule's substrate condition matches the verified substrate. Every set field must hold.

Field Values Rule applies when
checks check names, for example kosa8 The session was verified by one of these checks.
isolation none, process, gvisor, wasm, microvm, cvm, device-enclave The isolation is in the list.
notIsolation same The isolation is not in the list.
attestation none, inventory, measured The level is in the list.
notAttestation same The level is not in the list.

The gateway's JSON policy rules also take providers, regions, notRegions, countries and notCountries; the ToolPolicy CRD has the five fields above. A kosa8 check reports no jurisdiction. See ToolPolicy.

Ledger records#

Rule Server / tool Decision Written when
kosa8/audit-anchor kosa8 / audit observe kosa8d's chain verifies and its head seq changed since the last anchor. Reason: kosa8 audit chain verified through seq N (M entries).
kosa8/audit-unverified kosa8 / audit observe kosa8d reports a broken chain (once, until it verifies again), or the head went back (lower seq, or the anchored seq with another hash).

ext keys: kosa8AuditSeq, kosa8AuditHead, kosa8AuditVerified. A failed append is retried with backoff; the anchored position moves only once the record is in the ledger.

Mirrored mcp.decision record#

Field Value
action mcp.decision
actor agent
target maqpna/<namespace>/<agent>
detail <decision> by MAQPNA (ledger seq N), rule <policy/rule>
refs.session maqpna.<namespace>.<session>
refs.sandbox maqpna-<session>
refs.mcp phase: call, server, tool, allowed, rule, policy: maqpna, event: maqpna-ledger-<seq>, arguments (SHA-256 of the arguments)

kosa8d API calls#

All calls go to kosa8d's native API. State-changing calls send X-Kosa8-Actor: tool. TCP calls send Authorization: Bearer <token>. Non-streaming calls time out after 2 minutes (10 seconds in the gateway).

Method and path Body Used by
GET /kosa8/v1/health — dev up --kosa8
POST /kosa8/v1/sandboxes {name, cpus, mem_mb, egress, labels} dev run --kosa8-image
GET /kosa8/v1/sandboxes — Every lookup (there is no single-sandbox GET); broker check
DELETE /kosa8/v1/sandboxes/{id}?wipe=1 — Remove after dev run, failed re-key, refused restore
POST /kosa8/v1/sandboxes/{id}/pull {ref} dev run (the host pulls the image)
POST /kosa8/v1/sandboxes/{id}/start-interactive {image, args, env} dev run
POST /kosa8/v1/sandboxes/{id}/containers/{cid}/stdin the token line dev run (token delivery)
GET /kosa8/v1/sandboxes/{id}/containers — Attach, exec, re-key
POST /kosa8/v1/sandboxes/{id}/containers/{cid}/attach — Streams output (NDJSON)
POST /kosa8/v1/sandboxes/{id}/exec {container, args} Re-key a fork or restore
POST /kosa8/v1/sandboxes/{id}/fork {n: 1, prefix} dev fork
POST /kosa8/v1/sandboxes/{id}/snapshot {id} dev snapshot
POST /kosa8/v1/snapshots/{id}/restore {name} dev restore
DELETE /kosa8/v1/snapshots/{id}?wipe=1 — Driver DeleteSnapshot
GET /kosa8/v1/sandboxes/{id}/inventory — dev attest, broker check
GET /kosa8/v1/sandboxes/{id}/egress — dev run, dev restore, dev attest, broker check
GET /kosa8/v1/audit/verify — Gateway anchor
GET /kosa8/v1/audit?limit=1 — Gateway anchor (head entry)
POST /kosa8/v1/ai/records mcp.decision record Gateway mirror

Errors from kosa8d come back as kosa8: HTTP <status>: <error> (<remediation>).

Gateway routes used by dev snapshot and dev restore#

Route Auth Purpose
POST /v1/sessions/{id}/llamay:checkpoint admin token Checkpoint the session's llamay contexts (files under llamay.checkpointDir, .maqpna/checkpoints/llamay in dev).
POST /v1/sessions/{id}/llamay:restore admin token Bind the restored session to the checkpointed contexts. 403 when the checkpointed session is revoked.

Environment variables#

Variable Where Meaning
KOSA8_HOST your shell kosa8d TCP URL for the driver and the broker check (kosa8's own CLI reads it too).
KOSA8_TOKEN your shell Bearer token for KOSA8_HOST. Required with it.
MAQPNA_TOKEN_FILE in the sandbox /tmp/maqpna/token. Read it on every call.
MAQPNA_RUNTIME in the sandbox kosa8
MAQPNA_GATEWAY_URL in the sandbox http://<LAN IP>:8080
MAQPNA_SESSION, MAQPNA_AGENT in the sandbox The session and agent at start. After a fork or restore they still name the source; use the token's maqpna_session claim.
MAQPNA_TOOL_<NAME>_URL in the sandbox <gateway>/mcp/<name> per MCP server
OPENAI_BASE_URL, MAQPNA_MODEL_ENDPOINT, MAQPNA_MODEL_PROVIDER, MAQPNA_MODEL_NAME in the sandbox The model route, when one is configured. OPENAI_API_KEY is not set in a sandbox.

MAQPNA_TOKEN, and any variable whose value contains the token, are removed from a sandbox's environment.

Ports, sockets and files#

Item Value
kosa8d socket ~/.kosa8/run/kosa8.sock (mode 0600, no token)
kosa8d TCP kosa8 daemon start --listen ADDR, for example 127.0.0.1:7440; token in ~/.kosa8/worker-token
Gateway <LAN IP>:8080 with --kosa8 (--gateway-port)
Identity broker 127.0.0.1:8081 (--identity-port)
llamay 127.0.0.1:11435 (--llamay-port)
Local state .maqpna/state.json ("kosa8": true), .maqpna/gateway.json, .maqpna/audit.jsonl, .maqpna/logs/
Checkpoints .maqpna/checkpoints/<id>.json (sandbox snapshot and llamay contexts)

Metrics#

On the gateway's /metrics:

Metric Type Meaning
maqpna_gateway_kosa8_mirror_total{outcome="ok"\|"error"\|"dropped"} counter Decisions mirrored to kosa8, failed, or dropped because the queue was full.
maqpna_gateway_kosa8_audit_verified gauge 1 while kosa8d reports its chain verified. Only with the anchor on.
maqpna_gateway_kosa8_audit_head_seq gauge kosa8 audit seq last anchored. Only with the anchor on.
maqpna_gateway_kosa8_anchor_append_failures_total counter Anchor records the ledger could not append (retried). Only with the anchor on.

Errors#

Error Where Meaning
kosa8d unreachable (is `kosa8 daemon start` running?): … client No answer on the socket or URL.
kosa8: invalid daemon URL "…" client KOSA8_HOST is not an http(s)://host URL.
kosa8: a TCP daemon needs a token (kosa8d --token / KOSA8_TOKEN) client KOSA8_HOST without KOSA8_TOKEN.
cannot find this host's LAN address (use --kosa8-host-ip) dev up No default route.
--kosa8-host-ip must be a non-loopback IPv4 address dev up Bad --kosa8-host-ip.
sandbox: egress is not pinned to the gateway: … driver, dev attest The gateway is on loopback, or kosa8 enforces another policy.
kosa8sandbox: deliver the token: … dev run The token could not be written to stdin; the sandbox is removed.
sandbox: copy could not be re-keyed: <name> (removed): … dev fork, dev restore The copy was removed.
session S has no kosa8 sandbox (start it with dev run --kosa8-image ... --kosa8-keep): … dev fork No kept sandbox for that session.
checkpoint X was taken with driver Y, not kosa8 (use --sandbox Y) dev restore Wrong --sandbox.
restored sandbox <name> removed: … dev restore Egress check failed, or the gateway refused the llamay restore (403, revoked session).
kosa8: fork returned N clones, want 1 dev fork Unexpected kosa8 answer.
mint: HTTP 403 identity: proof refused: … broker, as maqpna dev prints it See Identity broker flags.
sandbox: driver not admitted: … dev The driver is weaker than microvm or lacks fork or snapshot.

Next steps#