# Modes, capabilities, sandbox

<p class="generated-note">Generated from <a href="https://github.com/altasystem-ai/alta/blob/main/docs/standards/hosted-mode.md"><code>docs/standards/hosted-mode.md</code></a> · <code>npm run docs:gen</code></p>

Tests: [`tests/runs.test.ts`](https://github.com/altasystem-ai/alta/blob/main/tests/runs.test.ts).

Status: **alpha**. This format can still change before its 1.0; a change follows the versioning rules of the project and is announced in the changelog.

## Modes ([`server/lib/mode.mjs`](https://github.com/altasystem-ai/alta/blob/main/server/lib/mode.mjs))

One switch: `--hosted` or `WORLD_MODE=hosted`. No other "cloud" branch outside `server/host/` (H1) and
[`client/features/hosted/`](https://github.com/altasystem-ai/alta/tree/main/client/features/hosted).

| | Local | Hosted |
|---|---|---|
| Listen | 127.0.0.1 | `WORLD_BIND` (the VM's private address) |
| Auth | `X-World-Token` (random, once by the URL) | `X-World-Auth` signed by the gateway, no token in the browser |
| Origin | the local origin | `WORLD_PUBLIC_ORIGIN` (https), and `Host` must be its host |
| `/api/game.host` | `{ os, arch, mode: "local", has: [gui, audio, keychain, terminal, …], machine }` | `{ os: "linux", mode: "hosted", has: [], machine }` (overrides: `WORLD_HOST_HAS`, `WORLD_HOST_MACHINE`; `machine`: [resources](resources)) |

Signature: `X-World-Auth: v1.<unix seconds>.<hex HMAC-SHA256(WORLD_HOST_SECRET, "<s>\n<METHOD>\n<path+query>")>`,
valid ±60 s, on every request. `WORLD_HOST_SECRET` is at least 32 characters. `modeProblems()` lists what is
missing; the server exits 2 if anything is. Helpers: `sign`, `signedOk`, `hostOk`, `originOk`, `describeHost`.

`describeHost()` adds, in hosted mode only, `tier` from `WORLD_TIER` (`free` or `paid`; set by the control plane,
refreshed by H1 through `/api/host`) and, in both modes, `axis` from `WORLD_AXIS` (`^[a-z][a-z0-9-]{0,31}$`, else
ignored), `arm` from `WORLD_ARM` (same shape) and `item` from `WORLD_ITEM` (`^[a-z0-9][a-z0-9-]{0,47}$`). The control
plane sets all three when it gives a VM its identity (`alta.control/0.2`, [`cloud/control/core/control.ts`](https://github.com/altasystem-ai/alta/blob/main/cloud/control/core/control.ts)). A hosted server proves `core.arrive` ([`server/checks/proven.mjs`](https://github.com/altasystem-ai/alta/blob/main/server/checks/proven.mjs)).

Routes of a hosted world toward its control plane ([`server/routes/host.mjs`](https://github.com/altasystem-ai/alta/blob/main/server/routes/host.mjs), through the world agent on 127.0.0.1,
which adds the VM's own secret; in local mode they send nothing):

| Route | What |
|---|---|
| `GET /api/host` | `{ mode, tier, endsAt, energy }`: the end of a free world and the LLM energy left |
| `POST /api/host/events` | `{ type: quest \| first-reply \| heard \| paywall, value?, detail? }`: the funnel, no content |
| `GET /api/host/plans` | the paid plans a free world can become (sizes, monthly prices, what each runs) |
| `POST /api/host/checkout` | `{ plan }` → `{ url }`: the payment provider's page for this world. The card is typed there only, never in the game; the world becomes paid only by the provider's signed webhook, on the same VM (bigger, no end). |

The checkout route needs no capability: it moves no money, it only opens the provider's page (`pay` stays for
executors that would pay from the game).

The client reads `?host=local|hosted|hosted-paid` and `?axis=<id>` only when the world served is the demo state (or
there is no server): they replace the host shown (never the capabilities or the authentication). On a real world they
are ignored.

## Capabilities ([`server/lib/caps.mjs`](https://github.com/altasystem-ai/alta/blob/main/server/lib/caps.mjs))

`ask`, `install`, `setup`, `forge`, `pay`, turned on by `--allow-<cap>`. Hosted opens `ask` and `install` by default
(`--no-ask`, `--no-install` to close). `pay` stays off everywhere until decision P3. `/api/game` gives `caps`.
A route or executor whose capability is off answers 403 with the flag to use.

## Sandbox ([`server/lib/sandbox.mjs`](https://github.com/altasystem-ai/alta/blob/main/server/lib/sandbox.mjs))

`WORLD_SANDBOX=1` (every test): `assertSandbox(home)` refuses a home outside the temporary directory or equal to
the real home, and `bins` refuses any program outside [`tests/fakes/`](https://github.com/altasystem-ai/alta/tree/main/tests/fakes). No test reads the real home or calls the real
`openclaw`.
