# nanovm: Deploy
https://nma.sh/llms.txt is the whole guide.
## Deploy
### First Deploy Checklist (in order)
1. Sign up: ssh nma.sh signup --json (your SSH key becomes your account; unverified: 2 apps at a time, so before a third app, or anything your human means to keep, give them the answer's claim_url or run verify EMAIL with their address: ask them for it, never make one up, since a made-up address bounces and the account stays unverified)
2. Deploy: ssh nma.sh deploy APP --json < app.js (creates APP; any program piping into ssh works)
3. Secret: ssh nma.sh secret set APP NAME --json < secret.txt (before or after the first deploy; never read back)
4. Status, logs, back: apps --json; logs APP --json (NDJSON); rollback APP --json; delete APP --json
A list that survives redeploys (a guestbook, a todo list): one db key per entry, read back with db.list.
db.put("gb:" + Date.now() + ":" + crypto.randomUUID(), msg); // keys sort by time
const { keys } = db.list("gb:", { limit: 50 }); const msgs = keys.map(k => db.get(k));
A private app (an admin view): secret set APP NV_BASIC_AUTH < pw.txt (a password, or USER:PASSWORD), and the browser asks for it
before your handler runs (public/ files are not covered). Per path: check "Bearer " + secrets.get("ADMIN_TOKEN"), or the sign-in of /examples/admin-page.js on this site. User accounts, no setup: const r = auth.handle(req); if (r) return r; serves /signup /login /logout /recover /reset (fields user and pass; /recover takes user, code and new; as a form or JSON; state changes POST-only; a JSON body gets {"ok":true,"user":...,"token":...}: send Authorization: Bearer TOKEN); then const u = auth.user(req) gives null or { id, user, db, kv } (db and kv as above) keyed to that user alone; auth.require(req) gives that user or, with no session, the answer to return (a 401, or for a browser a 303 to /login): const u = auth.require(req); if (!u.id) return u. If auth.require(req) guards /, deploy still succeeds (exit 0) and "first" shows 401 with a "note" (a browser goes to /login). See /examples/auth.js (whole app) and /recipes.txt (both user recovery codes and admin reset links).
### The Four Doors
All four doors share one data plane and contract:
1. SSH door: ssh nma.sh COMMAND [--json] (your SSH key is your login)
--json goes anywhere among the command's words. To put it first, write `--` before it: ssh nma.sh -- --json apps
2. CLI: nanovm --json [--url IP:PORT] [--creds DIR] COMMAND (or NANOVM_JSON=1)
Install (Linux x86_64, macOS x86_64): curl -fsSL https://nma.sh/dl/install.sh | sh
It checks https://nma.sh/dl/SHA256SUMS and unpacks nanovm, nanovm-dev and nanovm-framework/ into ~/.nanovm. The control
API is not public: use the CLI for pack and dev, the SSH door for the rest (nanovm pack . | ssh nma.sh deploy APP --json).
3. HTTP control API: /v1/..., every request signed with your key (CONTROL-API.md in the source), on the operator's own network
4. MCP stdio: nanovm [--url IP:PORT] [--creds DIR] mcp (protocol 2025-06-18).
Add to an MCP client: {"command": "nanovm", "args": ["mcp"]}; use NANOVM_URL and NANOVM_CREDS, or put --url and --creds before mcp in args.
No CLI needed: ssh nma.sh mcp speaks the same protocol under your SSH key's account ({"command":"ssh","args":["nma.sh","mcp"]}); run ssh nma.sh signup once first. It has every tool but deploy's local directory (send files instead). A call stops after 300 s, a session after 600 s idle or 3600 s in all; reconnect.
The local nanovm mcp needs a CLI login first. Tools: deploy {app?, source} (or {app, files} or {app, directory}: directories below), apps {}, deployments {app},
rollback {app, version?}, promote {app, version}, logs {app, version?, limit?}, delete {app}, secret_set {app, name, value},
secret_delete {app, name}, verify {email}, plan {}, upgrade {}, billing {}, whoami {} (tenant, key, role, latest_idempotency_key),
retry {} (finish a change whose answer was lost), usage {} (metered requests and bytes), keys {} (key ids, roles, states),
keys_create {id, role} (its secret, printed once), keys_revoke {id}, domain_add {app, host}, domains {}, domain_remove {host},
rename {app, name}, db_list {app, prefix?, after?, limit?}, db_get {app, key}, db_delete {app, key}, db_export {app} (up to 8 MiB).
Each tool runs the same CLI with --json; its stdout is the result text (logs: NDJSON).
Any nonzero exit is isError, including exit 3: the new version's first request answered 5xx.
Source and secret values go on the child's stdin, never argv. Secrets are write-only; set one before or after deploy.
logs reads recent lines and ends (no follow), with limit 1..1000 and optional version.
MCP requests are newline-delimited JSON-RPC 2.0 objects, at most 1 MiB per line.
With --json (or NANOVM_JSON=1), stdout is one JSON object per answer (logs: NDJSON), nothing else; exit codes stay the same.
### Directories, archives and static sites
Every door deploys folders through one packer (same names, limits, checks) as one deterministic archive, in one of two shapes:
- An app: app.js at the top, and public/ for files served as they are; public/index.html also answers "/".
Its other JavaScript files can use relative require; no npm install runs. Files answer only at their own
names (public/about.html is /about.html): /about, like any other miss, goes to app.js. Pretty URLs are the static site's.
- A static site: index.html at the top, no app.js or package.json, no code of your own. /about answers about.html, /docs/ answers docs/index.html, an unknown path 404 (your 404.html if there is one). Optional `_headers` and `_redirects` settings apply to its static answers (they are never served as files), parsed at deploy and refused there with the wrong line named.
- `_headers`: a path line, then indented `Name: value` lines; a path is exact or ends with one `*`; at most 100 rules and 8 KiB. Content-Length, Transfer-Encoding, Connection, Set-Cookie, hop-by-hop, ETag, Location and other answer-owned headers are refused; every matching rule applies, the last of a name wins.
- `_redirects`: `FROM TO [STATUS]`, FROM exact or ending in one `*`, with `:name` as a whole segment; TO may use `:name` and `:splat`; STATUS 301 (default), 302, 307, 308 or 200 (serve TO's file); first match wins, an existing file wins over a rule, at most 200 rules. `/* /index.html 200` alone is still the single-page app: every unknown path answers index.html with 200.
Archives may wrap the folder in one top directory; __MACOSX/, ._* and .DS_Store are dropped.
- SSH, no CLI: tar czf - -C DIR . | ssh nma.sh deploy APP --json (or zip -qr - . from DIR).
Any tar (ustar, GNU, pax), gzip'd tar or zip. Refused: links, devices, names with .. or a leading /,
.env files, a damaged archive, one past the limits, and no app name (missing_name). Never unpacked on the host.
- CLI (with --url, on the operator's network): nanovm deploy APP DIR (or an archive file); nanovm pack DIR|ARCHIVE|- prints the archive; nanovm dev DIR runs either shape locally.
- HTTP: POST /v1/apps/APP/deploy-tree with the archive from nanovm pack, signed as usual.
- MCP deploy: {"app":"APP","files":{"index.html":"
hi
","css/site.css":"h1{}"}} (text files); the
CLI's mcp also takes {"app":"APP","directory":"/absolute/path"}, a path on the MCP server's machine.
- Web panel: the directory picker sends the folder as it is, so give it app.js and public/.
Static files need no VM: the edge answers GET and HEAD from public/ (and a static site's /about, SPA and 404 answers), with ETag, Range, gzip and br. Content-Type comes from the suffix (html css js mjs json txt md xml svg png jpg jpeg gif ico webp avif wasm woff woff2; others application/octet-stream).
A tree deploy adds static_base and, with public/index.html, page_url, the version-qualified page. A handler gets req.staticBase; append an asset's path to pin its version.
- Vite (vanilla TS or React SPA): npm ci && npm run build, then nanovm deploy APP dist (not the project root with
package.json). Vite copies public/_redirects into dist/, so deep links like /about answer index.html with 200.
SSR output is not deployable (built client files only, no Node server or Vite middleware). Verified with vite 8.3.8
and node 22.22.1 (npm ci + npm run build); nanovm dev dist answered /, /about and /assets/*.
### SEO for public apps
- Prefer SSR (serve(), static HTML, or framework via nanovm pack .) over a Vite SPA; return 404, not 401, on missing paths.
- Add viewport, unique , description, , canonical, og:title/description; serve /robots.txt and /sitemap.xml.
- On Pro custom domains, emit absolute canonicals or 301 other req.headers.host; send X-Robots-Tag: noindex on private routes.
### Signing Up
- SSH: ssh nma.sh signup [INVITE] [--ref TAG] --json; a key from `keys create` (role owner hands your human the account) attaches with ssh nma.sh login ID < secret.txt (the secret on stdin; or nanovm login ID - on the operator's network)
- Free tier, unverified: 2 apps at a time (deleting one frees its room at once; an account already past 2 keeps its apps) and 3 keys (the same on every tier). It's a starter sandbox before you attach an email. verify EMAIL (the CLI, the door, MCP's verify; an owner key) mails your human a link (good for 24 hours); once they press Confirm the account has 5 apps at a time (deleting one frees its room at once) and its apps are kept for good. Every app takes a number for the account's life that is never reused: 16 at most. apps_full or keys_full past them. Ask your human for an email before a third app, or before you deploy something they mean to keep. The deploy, tenant and sign-up answers also give `claim_url` (when the account is not verified or not Pro): give it to your human to open in a browser; that page confirms the email or pays for Pro without the SSH key.
- Pro ($8 a month, paid through Stripe): upgrade (any owner key, no email needed; MCP's upgrade) prints a checkout link for your human. Pro is never needed to keep idle apps (a verified free account already keeps its apps for good); Pro gives 10 apps at a time on nma.sh, a bigger db and kv share (plan prints the numbers), custom domains (domain add), rename, and daily backups: backups APP lists the last 7 days' copies of the app's db and kv, restore APP DATE writes one back (it overwrites keys, never deletes newer ones; the copies are kept on the same host, a guard against mistakes, not disk loss; db export APP is the copy you keep yourself). plan shows what Pro gives on this server, the plan, and usage: apps used of the cap, db keys of the share a group, kv keys of the cap. billing (an owner key) prints a Stripe link where your human changes the card, sees invoices or cancels (Pro lasts to the end of the period paid). apps_full and a db or kv quota error name Pro and its command. Offer it only when your human wants more.
- HTTP, on the operator's network: POST /v1/signup with {"key_hash":"<64hex>"} (or {"tenant":T,"invite":"","key_hash":"<64hex>"}, optional "ref":"TAG") -> 201 {"tenant":1,"key":65,"role":"owner"}
### Commands and JSON Shapes
### apps / app / apps create
Your tenant's apps; one app; an empty slot (deploy makes one too). "state": live, warned (idle), deleting (idle, a day from removal), deleted.
- Door: apps
- CLI: nanovm --json apps | app APP | apps create NAME
- HTTP: GET /v1/apps | GET /v1/apps/APP | POST /v1/apps {"name":"NAME"}
- Output: {"apps":[{"name":"web","app":1,"generation":1,"current_version":1,"versions":1,"secrets_generation":0,"state":"live","url":"https://assured-tableland.nma.sh/","numeric_url":"https://1-1.nma.sh/"}]}
app APP: one of those objects. apps create (201): {"name":"web","app":1,"generation":1}
### deploy
Send the source; it is built, snapshotted and live in one call. Creates the app if it is new; sending the same source again is safe.
- Door: deploy APP < app.js
- Door: deploy APP < site.tgz (a folder as a tar, tgz or zip; see "Directories, archives and static sites")
- Door: deploy-tree APP < app.tar (the archive nanovm pack DIR prints)
- CLI: nanovm --json deploy APP app.js (or deploy APP VERSION FILE)
- HTTP: POST /v1/apps/APP/deploy (body is JS source)
- A FILE of "-" is stdin: `cat app.js | nanovm --json deploy APP -`.
- No name: `deploy < app.js` (door), `nanovm --json deploy app.js`, POST /v1/deploy with an Idempotency-Key:
a new app with a generated name like "quiet-river-7k2", given back as "app" in the output.
- Output (200):
{"app":"web","version":1,"digest":"<64hex>","status":"live","new_version":true,"url":"https://assured-tableland.nma.sh/","numeric_url":"https://1-1.nma.sh/","build":["step 1"],"first":{"status":200,"ms":15},"message":"web is live (version 1): https://1-1.nma.sh/","claim_url":"https://nma.sh/c/"}
### deployments
- Door: deployments APP
- CLI: nanovm --json deployments APP
- HTTP: GET /v1/apps/APP/deployments
- Output: {"app":"web","generation":1,"deployments":[{"version":1,"digest":"<64hex>","current":true}]}
### rollback / promote
- Door: rollback APP [VERSION]
- CLI: nanovm --json rollback APP [VERSION] (or promote APP VERSION GENERATION)
- HTTP: POST /v1/apps/APP/rollback (or POST /v1/apps/APP/deployments/V/promote)
- Output: {"app":"web","version":1,"generation":2,"first":{"status":200,"ms":12},"message":"web is back on version 1"}
It answers once the URL serves that version, as deploy does ("first"; null if not within 10 s).
### delete
Delete an app you own (an owner key): its URL answers 404 at once, and "state" is "deleted". Deploy it again to bring it
back, on the same URL, as a new version; a rollback or promote of it is refused (app_deleted). A day later (grace_s) its
versions are removed. Its kv, db and crdt data are the tenant's and stay. Its number stays used for good; deleting it frees the room it held at once (apps_full), and deploying it again needs room like a new app.
- Door: delete APP
- CLI: nanovm --json delete APP (or app delete APP)
- HTTP: DELETE /v1/apps/APP with If-Match: its generation
- Output: {"app":"web","deleted":true,"state":"deleted","generation":3,"grace_s":86400,"first":{"status":404,"ms":3},"message":"..."}
It answers once the URL answers 404 ("first"; null if not within 10 s). Deleting it again gives the same answer.
### logs
- Door: logs APP [-f]
- CLI: nanovm --json logs APP [-f] [--version V] [--limit N]
- HTTP: GET /v1/apps/APP/logs[?follow=1&version=V&limit=N]
- Output: One JSON object per line (NDJSON):
{"cursor":"5-9","start":true}
{"cursor":"5-10","ms":1710000000000,"vm":"1.6","version":1,"line":"listening on port 80"}
{"cursor":"5-11","missed":40} (lines dropped because this reader was slow: how many)
{"cursor":"5-12","end":true} (not with -f; a follower gets {"ping":MS} when quiet)
"ms" is the line's time in Unix milliseconds; "vm" is POOL.VM; "version" the app version that printed it.
### secret set / delete
Write-only secrets for an app. Secrets are injected into VMs; no API returns their values.
- Door: secret set APP NAME < value | secret delete APP NAME
- CLI: nanovm --json secret set APP NAME [GENERATION] < value | secret delete APP NAME [GENERATION]
- HTTP: PUT /v1/apps/APP/secrets/NAME {"value":"..."} | DELETE /v1/apps/APP/secrets/NAME
- APP need not exist yet: a set before its first deploy is kept for that name (no app slot; `apps` lists nothing), and that deploy starts with it.
- In the app: secrets.get(NAME) returns the value as of now (a change reaches a running VM at its next
lookup, with no redeploy). A name this app does not have throws "no secret NAME for this app".
Call secrets.get inside the handler, never at top level: top level runs once at build time, so a value read
there would be frozen into the snapshot and miss every later change. Pattern:
let secret; try { secret = secrets.get('NAME'); } catch (e) { secret = null; }
- Output: {"app":"web","name":"TOKEN","written":true,"secrets_generation":1} (delete: "deleted":true)
### db list / get / delete / export (your account's db from outside an app; owner key)
The same keys your apps' db sees, read strong, never another account's. APP is any app of yours, even deleted.
- Door: db list APP [PREFIX] [--after K] [--limit N] | db get APP KEY | db delete APP KEY | db export APP
- CLI: nanovm --json db VERB APP ...; any key (spaces too): db get|delete APP --body - with {"key":"..."} on stdin
- HTTP: POST /v1/apps/APP/db/list {"prefix","after","limit"} | db/get, db/delete {"key"} | db/export {"after"?}
- Output: list {"app","keys":[...],"next":KEY|null}; get {"app","v":N,"value":"..."} (not_found: no value);
delete {"app","deleted":true|false}; export: NDJSON {"key","v","value"} lines, last {"end":true,"keys":N}.
- These commands from outside an app, not an app's own db calls: 120 calls a minute an account (an export is 10), 2 at once: slow_down with retry_after_s, too_many_readers.
### retry (resend the last mutation whose outcome was unknown)
- Door: retry CLI: nanovm --json retry -> the definite server response, or {"pending":false,"message":"nothing pending"}
### domain add / ls / rm (Pro: your app at your own host name, over TLS; MCP domain_add, domains, domain_remove)
- Door: domain add APP HOST | domain ls | domain rm HOST CLI: nanovm --json domain ... HTTP: POST /v1/domains {"app","host"}, GET /v1/domains, DELETE /v1/domains/HOST
- add -> {"host","app","state","why","record":{"type":"CNAME","name":HOST,"value":"NAME.nma.sh"},"message"}: your human sets that record (a bare domain: type "A", value the server's address). HOST is served once the server sees its DNS point here and its certificate is issued; state is pending_dns, pending_cert, live, or failed with why. A host another account holds is domain_taken; a free account gets pro_only; 10 host names an account for its life, re-adding one is free (domains_full).
### rename APP NAME (Pro: a name you choose, NAME.sites.diy; MCP rename)
- Door: rename APP NAME CLI: nanovm --json rename APP NAME HTTP: POST /v1/apps/APP/rename {"name":"NAME"} — five or more letters, a-z, 0-9 and inner hyphens, at most thirty, filtered; once taken it is never another app's; the two-word URL and N-TENANT keep working; a free account gets pro_only and the upgrade line. The chosen name lives on sites.diy, never under nma.sh: nma.sh is the free, open-signup domain and its names are the two random words and N-TENANT.
- Door: backups APP | restore APP DATE (Pro; MCP backups, restore; HTTP GET /v1/apps/APP/backups, POST /v1/apps/APP/backups/DATE/restore): a daily copy of the app's db and kv, the last 7 UTC days; restore writes each key back as one new version, keys added since stay, and running it again finishes an interrupted one (CONTROL-API.md "Backups").
### keygen / login / keys / tenant (CLI; tenant and keys are MCP whoami, keys, keys_create, keys_revoke)
- Door: tenant | usage | keys | keys create ID ROLE | keys revoke ID | login ID < secret
- keygen: nanovm --json keygen -> {"secret":"<64hex>","key_hash":"<64hex>"}; login: nanovm --json login ID SECRET -> {"logged_in":true,"key":ID}
- tenant: nanovm --json tenant -> {"tenant":1,"key":65,"role":"owner","latest_idempotency_key":78,"apps_used":1,"apps_cap":2,"email":"none","plan":"free","pro":"...","claim_url":"..."} (email is "none", "pending" once a link is sent, or "verified" once your human confirms, when apps_cap goes to 5); usage: nanovm --json usage -> {"tenant":1,"meters":0,"requests":0,"ingress_bytes":0,"egress_bytes":0}
- keys: nanovm --json keys -> {"tenant":1,"keys":[{"id":65,"role":"owner","state":"live","generation":1}]}; keys revoke ID -> {"id":66,"state":"revoked","generation":2}
- keys create: nanovm --json keys create ID ROLE (ID an unused integer, ROLE owner, deployer or reader) -> {"id":66,"role":"deployer","tenant":1,"generation":1,"secret":"<64hex>"}
### verify / plan / upgrade / billing (owner key; MCP verify, plan, upgrade, billing)
- verify EMAIL -> {"email":"","sent":true,"expires_in_hours":24,"apps_after":5,"message":"..."} (already verified: {"email","verified":true,"sent":false}); plan -> {"plan":"free","apps_cap":2,"apps_used":1,"pro":{"price":"$5 a month","apps":10,"db_keys_a_group":12288,"db_bytes_a_group":50331648,"kv_keys":2048,"kept_idle":true},"free":{...},"grace_days":7,"pro_caps_left_s":0,"next":"..."}; upgrade -> {"plan":"pending","checkout_url":"https://checkout.stripe.com/...","price":"$5 a month","apps_after":10,"message":"..."} (on Pro: {"plan":"pro","already":true,"apps_cap":10,"message"}); billing -> {"portal_url","billing_email","message"}
### dash (your human's browser; MCP not needed)
- Door: dash | dash signout
- dash -> one line, https://nma.sh/dash#t=TOKEN: opening it signs that browser in to this account's dashboard with this key's role (a reader key gives a reader's view). It works once, within 5 minutes; the sign-in lasts 8 hours in that tab, takes no key id and no key slot, and works on a free account. Give the link to your human only; a second open says it was used. With --json: {"url":"...","role":"owner","expires_in_s":300,"session_s":28800}. A dashboard sign-in cannot make keys or links.
- dash signout (owner key) -> every browser signed in to this account is signed out at once; revoking the key that made a link does the same for its sign-ins.
### help
- Door: help [--json] -> {"commands":[{"command","usage","description"},...],"cli_only":"...","llms_txt":"/llms.txt"}: every door command; cli_only names the CLI's own (app, apps create, keygen, pack, dev).