# Unattended agents

An AI agent can take the SDK from nothing to a running project with no person present: the HTTP API, `sona`,
`sona-mcp`, the tools installers, the library and the web SDK all work with stdin closed and no terminal or screen.
None of them asks a question, waits for a key, or opens a window or a browser. When a value is missing they exit at
once with a sentence that names the flag or variable to set.

Three things stay with a person, and each is done once, ahead of time, in writing:

- the contact address on the app request (where 360sona writes about the app);
- the two typed sentences, for the Developer Terms and the SDK Licence, which the server records with the app and the
  time;
- the MCP server's grants (more write folders, building edited projects), written as flags, variables or a config file.

SDK Studio is where a person is asked. Nothing on this page needs it. Player sign-in ("Sign in with 360sona") is for
a game's players and uses a browser by design; an agent building the game does not need it.

| To | Use | Needs |
|---|---|---|
| Get an app id and key | `POST /sona/v1/requests` or `sona app request` | the Developer Terms sentence, a contact address |
| Get the tools | `GET /sona/v1/apps/{id}/tools?platform=` or `sona app tools` | the app key |
| Install them | `./install.sh`, or `setup.exe --quiet` | nothing |
| Accept the SDK Licence | `POST /sona/v1/apps/{id}/sdk-licence` or `sona app licence --agree` | the SDK Licence sentence |
| Get the SDK made for the app | `sona app download <platform> --unpack <folder>` | the licence accepted |
| Get avatar files | `--gate` (from 360sona), or `--dir <dump folder>` | the network, or a dump you own |
| Draw, export, check | `sona render`, `sona export`, `sona avatar validate` | `SONA_SDK`, avatar files, a Vulkan driver |
| Drive it from an agent | `sona-mcp --sdk <folder>` | grants set before it starts |
| Draw in a web page | `SonaRenderer.create({ canvas, host })` | the page's origin registered |

What reaches the network: `sona app` commands, the downloads and every gate source go to `SONA_SERVER` (default
`https://test.360sona.com`; in the library, `config.check_host`, the same default). A `--dir` source makes no network
call. The web SDK goes to its `host` (default `https://360sona.com`; test.360sona.com is the same service).

## 1. An app id and key

A read-only app (`wants: lookup`) is approved at once. The key is shown once, in this reply.

```sh
curl -s https://360sona.com/sona/v1/requests -H 'Content-Type: application/json' -d '{
  "kind": "access", "app": "My Game", "contact": "you@example.com",
  "about": "A game that shows its players their Xbox 360 avatars.",
  "agree": "I have read and understand the Developer Terms"}'
```

```json
{ "ok": true, "id": "req_...", "approved": true,
  "app": { "id": "my-game-3f9a", "key": "sak_...", "wants": ["lookup"], "scopes": [] } }
```

`contact` is the address of the person who runs the agent; an agent with none of its own asks for it in its
instructions, not at run time. `agree` must be the sentence exactly, after reading <https://360sona.com/devterms.html>.
Every scope (`profile:write`, `avatar:write` and `xbox` too) is granted with the app; a new app's limits grow with its
age (100 players the first week, 1,000 the first month). A name too close to 360sona, Xbox or Microsoft, or one
another app has, is refused with a 400 and the reason.

An app made this way belongs to no account yet. To see it in [Your apps](https://360sona.com/devapp.html), and download Setup
for it there, sign in and open **Add an app you already have** with its id and key.

With the tools installed, the same request writes the key to a file and never prints it:

```sh
sona app request --name "My Game" --contact you@example.com --about "A game that shows avatars." \
  --agree "I have read and understand the Developer Terms" --app-key-file ~/.config/360sona/app.key
```

Then every `sona app` command reads `SONA_APP` and `SONA_APP_KEY_FILE` (or `SONA_APP_KEY`), and `SONA_SERVER`
when the server is not `https://test.360sona.com`.

## 2. The tools

`GET /sona/v1/sdk` lists the installers under `tools` (`platform`, `file`, `version`, `sha256`, `bytes`): one per
system (`linux-x64`, `windows-x64`, `macos`), the same for every developer.

```sh
export SONA_APP=my-game-3f9a SONA_APP_KEY=sak_...
curl -s -H "Authorization: Bearer $SONA_APP_KEY" -OJ \
  "https://360sona.com/sona/v1/apps/$SONA_APP/tools?platform=linux-x64"
sha256sum 360sona-sdk-tools-*-linux-x64.tar.gz     # the sha256 GET /sona/v1/sdk lists
tar xzf 360sona-sdk-tools-*-linux-x64.tar.gz
sh 360sona-sdk-tools-*-linux-x64/install.sh       # asks nothing; ~/.local, or --prefix <dir>
export PATH="$HOME/.local/bin:$PATH"               # the line install.sh prints; a root shell has no ~/.local/bin on PATH
sona version
```

Later copies come with `sona app tools <platform>`, which checks the SHA-256 before it writes the file.
`360sona-uninstall` removes them, with no question.

Windows, from PowerShell or any program:

```text
curl.exe -s -H "Authorization: Bearer $env:SONA_APP_KEY" -OJ "https://360sona.com/sona/v1/apps/$env:SONA_APP/tools?platform=windows-x64"
.\360sona-sdk-tools-<version>-windows-x64-setup.exe --quiet
```

`--quiet` (or `/S`) installs for the user with no window, adds `bin` to the user's PATH (a new shell sees it) and
registers the uninstaller. `--prefix <dir>` picks the folder; `--no-path` leaves PATH alone, and the last line then
names the `bin` folder to run `sona.exe` and `sona-mcp.exe` from. Started by a program without `--quiet` (its output
piped or redirected, or `SONA_UNATTENDED` or `CI` set), the setup program opens no window: it changes nothing and
exits 2, saying to pass `--quiet`. `uninstall.exe --quiet` removes it the same way. The programs need no DLL beyond
Windows' own.

## 3. The SDK Licence and the download

```sh
sona app licence --agree "I have read and understand the SDK Licence"
sona app download linux-x64 --with-catalogue --unpack ~/sona-sdk
export SONA_SDK=~/sona-sdk
```

Without `--agree`, `sona app licence` changes nothing, prints where the licence is
(<https://360sona.com/devterms.html#sdk-licence>) and the sentence, and exits 2. With it, the server records the app
and the time, and the reply carries `accepted_at`. Over HTTP it is `POST /sona/v1/apps/{id}/sdk-licence` with
`{"agree": "<the sentence>"}`, then `GET /sona/v1/apps/{id}/sdk?platform=linux-x64&catalogue=1` for the zip.

The download is made for the app and a new build id. `--unpack` writes it into the folder with no unzip; a second
unpack over it is refused unless `--force`. It holds:

| Path | What |
|---|---|
| `sona-licence.json` | the licence for this app and build |
| `bin/sona`, `bin/sona-mcp` | the tools stamped for this app and build (`.exe` on Windows; `bin/sona.dll` too) |
| `include/`, `lib/` | headers and the library your code links |
| `bindings/` | C++, Rust, Python and C# bindings |
| `data/sona-catalogue.bin` | the offline catalogue (with `--with-catalogue`) |
| `README.md` | what the download is, and where the docs are |

The installed tools are the same for every developer, so their core opens no licence. With `SONA_SDK` set (or
`--sdk <folder>`), each command that opens the SDK runs in `bin/sona` of the download, with its licence and catalogue;
`app`, `docs`, `version` and `help` run in the installed tool. Without `SONA_SDK` such a command exits 6 and says to set it.

## 4. Avatar files and the CLI

A machine that starts from nothing has no avatar files. `--gate` reads them from 360sona over the network with the
app's licence, and is the way for such a machine. `--dir <folder>` (or `SONA_DIR`) reads a dump folder you own and
makes no network call. The catalogue (`--with-catalogue`) holds names and ids only, never item files.

Drawing needs a Vulkan loader and driver. On a Linux machine with no GPU, Mesa's lavapipe draws on the CPU:

```sh
apt-get install -y --no-install-recommends libvulkan1 mesa-vulkan-drivers   # Debian, Ubuntu; headless.md lists others
```

Without it, `render` exits 5 at once (`no GPU device for drawing: no Vulkan loader`) and names these packages.

```sh
sona catalogue search pirate --section costume --body man --json
sona avatar new -o me.txt
sona avatar dress me.txt "<a name from the search>" -o me.txt
sona render me.txt -o wave.png --clip GenericWave --time 1 --gate --json
sona export glb me.txt -o me.glb --rigged --clips GenericWave --gate --json
sona avatar validate me.txt --build --gate --json
```

With a dump folder instead, set `SONA_DIR=<folder>`, drop `--gate`, and add `--on-disk` to the search so it lists only
items the folder holds.

A picture or model that lacks a worn item is not that avatar: `render` and `export` still write the file, list the
items under `missing_items`, set `"complete": false` and exit 1. `--allow-missing` accepts it (exit 0, with a note).
`avatar validate --build` fails `items_found` the same way; `items_drawn` only reports items another item covers
(hair under a hat) and never fails the avatar.

The gate's server is asked once first, so with no network the command fails in seconds (exit 3) instead of waiting
`--timeout`. `--server <url>` (or `SONA_SERVER`) names another server. A release build checks the gate's licence over
https only: `--gate` with a plain `http://` server is refused at once (exit 2), so a test server of your own is used
with `--dir`.

## 5. The MCP server

```sh
claude mcp add sona -- sona-mcp --sdk ~/sona-sdk --gate --root ~/sona-projects
```

With `--sdk`, the server uses the download's licence and catalogue, builds projects against its `include/` and
`lib/`, and runs as the `bin/sona-mcp` made for the app. `--gate` or `--dir <folder>` gives it avatar files, as for
the CLI. `sdk_info` reports `made_for_app`, `sdk_include`, `sdk_library` and `grants`. Ending its input ends it
(exit 0).

Agents work inside `--root`. Two things are refused unless the person who starts the server granted them before it
started. Nothing asks at run time, and each refusal names the three ways to grant it:

| Grant | Flag | Variable | Config file key | Allows |
|---|---|---|---|---|
| More write folders | `--allow-write <folder>` (up to 8) | `SONA_MCP_ALLOW_WRITE` (`:` apart, `;` on Windows) | `"allow_write": [...]` | writes (renders, exports, files) in those folders too |
| Edited projects | `--allow-exec` | `SONA_MCP_ALLOW_EXEC=1` | `"allow_exec": true` | `project_build` and `project_run` of a project an agent changed, and more starter options |
| No write sandbox | `--allow-writes-anywhere` | none: a flag or key only | `"allow_writes_anywhere": true` | writes anywhere the user may write |

Writes into a project's `.sona/` folder are refused with no setting to allow them. A project made by
`project_create` and not changed builds and runs with no grant.

The config file (`--config <file>`, or `SONA_MCP_CONFIG`) takes the server's other settings too. A key the server
does not know, or a value of the wrong kind, stops it at start (exit 2): a grant is never guessed.

```json
{ "sdk": "/srv/agent/sona-sdk", "gate": true, "root": "/srv/agent/sona-projects",
  "allow_write": ["/srv/agent/renders"], "allow_exec": true, "jobs": 8 }
```

Keys: `sdk`, `dirs`, `gate`, `server`, `licence`, `catalogue`, `samples`, `filter`, `root`, `allow_write`,
`allow_writes_anywhere`, `allow_exec`, `sdk_include`, `sdk_library`, `jobs`, `cpu`. The environment goes over the
file (`SONA_MCP_ROOT` is `--root`), and flags go over both.

A run from nothing, as tool calls: `sdk_info`, `dress_from_text {text: "a pirate"}`, `render_avatar {save_to: "me.png"}`,
`export_avatar {save_to: "me.glb", rigged: true}`, `project_create {path: "game"}`, `project_build`, `project_run
{seconds: 8, args: ["--avatars", "12"]}` (`args` is an array of strings), `frame_stats`. After `project_write_file`,
`project_build` needs `allow_exec`.

On Windows, keep `--root` short (`C:\sona`): a project path over about 100 characters breaks Visual Studio builds
(MSB6003), and the build's failure says so. The starter copies `sona.dll` from the download's `bin` beside the program.

## 6. The web SDK

```sh
sona app origins add http://localhost           # any port; https://your-site for a real site
sona app download web --unpack ~/web/sdk
```

```js
import { SonaRenderer }
  from './sdk/360sona-renderer-sdk-<version>/sona-renderer.js';
const sona = await SonaRenderer.create({ canvas: document.querySelector('canvas') });   // host: see below
const avatars = manifests.map((m, i) => sona.add(m, { position: [(i - 1) * 1.1, 0, 0] }));
await sona.settle(avatars, { seconds: 120 });
const png = await sona.snapshot();             // a PNG Blob of the next frame
```

The SDK talks to one host, `https://360sona.com` unless `create` names another with `host`: the origin check
(`GET /sona/v1/sdk/check`), the asset bridge (a hidden frame at `/sona/v1/sdk/bridge/{app}`) and the CSP lines in
the zip's `README.md` all use it. To check a page with no person and no GPU, open it in headless Chromium with
`--headless=new --enable-unsafe-swiftshader` and read the picture from `sona.snapshot()` or a page screenshot; the
WebGL2 canvas read back with `drawImage` or `getImageData` is blank.

## 7. Your own program

The C and Python tutorials' programs are `hello.c` and `hello.py` (the [C tutorial](../tutorials/c.md) and
[Python tutorial](../tutorials/python.md) show them); save them beside your download.
Both draw one avatar waving to a PNG with no window.

```sh
cc -std=c99 -I "$SONA_SDK/include" hello.c -L "$SONA_SDK/lib" -lsona -Wl,-rpath,"$SONA_SDK/lib" -o hello
./hello "$SONA_SDK/sona-licence.json" ~/dump "$(sona avatar new)"
SONA_LIB_DIR="$SONA_SDK/lib" PYTHONPATH="$SONA_SDK/bindings/python" python3 hello.py "$SONA_SDK/sona-licence.json" ~/dump "$(sona avatar new)"
```

The library never prompts. A headless machine draws on the CPU Vulkan device (Mesa's lavapipe, `--cpu` in the tools;
[Headless rendering and video](headless.md)).

## Exit codes

| Code | `sona` | `sona-mcp` |
|---|---|---|
| 0 | done | its input ended |
| 1 | the answer is no: refused, not found, not approved at once, a picture or model without some worn items | it could not start (licence, sources, port) |
| 2 | bad or missing arguments, a sentence not given, a plain-http server for the gate in a release build | a bad flag, or a bad config file or variable |
| 3 | a file could not be read or written; the gate's server gave no answer | not used |
| 4 | an input did not decode | not used |
| 5 | not available here: no GPU device (the message names the driver packages) | not used |
| 6 | the SDK refused: the licence (with the setting that mends it), an avatar that did not build in time | not used |
| 7 | out of memory or a bug | not used |

`--json` puts the same result on stdout as one object, with `ok`, `exit` and `error`. A tool call that is refused
returns `isError: true` and the sentence; it never waits. The Windows setup program exits 0 installed, 1 failed, 2
not started (no `--quiet` with no person present).
