# Rune on a VPS: agent runbook Use this when you want Rune on a server only, with nothing installed on your laptop. Claude, Grok and other agents then load Rune skills over MCP. **For humans.** Give your agent one line: > Read https://raw.githubusercontent.com/Rune-kit/rune/master/docs/VPS-SETUP.md and set up Rune on my VPS `me@1.2.3.4`. The agent may ask whether you have a domain and which apps to connect. When it finishes you get a URL, where your key file is, and one setup line per app. **What the VPS does.** It only serves skills, meaning the instructions. Your agent still reads and edits code in its own workspace, on your laptop or in its cloud sandbox. The server never touches your repo. Hooks and bundled scripts don't run remotely. See [What runs where](SERVE.md#what-runs-where). --- ## Rules for the agent (read first) 1. **Never show the key.** Don't `cat`, `echo` or print `~/.rune/serve.key`, and never put the key in chat, a commit, a log, an issue or a URL. You may load it into a variable inside a command, e.g. `RUNE_KEY="$(cat ~/.rune/serve.key)" rune serve doctor`; that prints nothing. The `rune_sk_xxxx…` *hint* in reports is only a prefix and is safe to show. 2. **Run every command on the VPS.** If you are not on the VPS, wrap each one: `ssh me@host ''`. Commands under "Client config" run on the user's machine. 3. **Steps are idempotent.** Re-running a step is safe. Re-running `rune serve setup` keeps the existing key and a saved `--allow-query-key`. It restarts the server, and a quick-tunnel URL changes when that happens. Never add `--rotate-key` unless the user asks for it, because it disconnects every client. Turn `?key=` back off with `--no-allow-query-key`. 4. **Ask before anything outside this runbook.** Get a yes from the user before changing SSH config, before disabling a firewall, and when you would need someone's credentials. Use the user's own git credentials for private repos, and never paste tokens into commands. 5. **Check after every step.** Each step has a "Check" line. If it fails, see [Troubleshooting](#troubleshooting). Don't move on until it passes. ## Step 0: Decide (ask only what you can't detect) | Question | Default | Effect | |---|---|---| | SSH target (`user@host`) | (required) | where to run everything | | Does the user have a domain pointing at the VPS (e.g. `rune.example.com`)? | no | **yes:** Path A, Caddy with automatic HTTPS and a fixed URL. **no:** Path B, a Cloudflare quick tunnel. Its URL **changes on every restart**. | | Do they own Rune Pro / Business? | no | clone them in Step 3 | | Which apps to connect? | Claude Code | the lines you print in Step 7 | ## Step 1: Preflight ```bash uname -sm; id -un node -v 2>/dev/null || echo "node: missing" systemctl --user show-environment >/dev/null 2>&1 && echo "systemd-user: ok" || echo "systemd-user: no" command -v ufw caddy 2>/dev/null; true ``` Check: Linux on `x86_64` or `aarch64`, and Node **18 or newer**. If Node is missing or too old, do Step 1b. `systemd-user: no` is fine; Step 5 covers it. Use the account you SSH in with (root works too). ### Step 1b: Install Node (only if needed) Debian or Ubuntu: ```bash curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash - sudo apt-get install -y nodejs ``` For other distros, see https://nodejs.org/en/download. Check: `node -v` prints v18 or newer. ## Step 2: Install Rune ```bash npm i -g @rune-kit/rune@latest rune --version && rune serve --help >/dev/null && echo ok ``` Use a global install, not `npx`, so that the service has a stable path. If you get `EACCES`, run `npm config set prefix ~/.npm-global`, retry, and call `~/.npm-global/bin/rune` (or add that directory to `PATH`). Check: the version prints, followed by `ok`. ## Step 3: Pro / Business (optional) ```bash [ -d ~/rune-pro ] && git -C ~/rune-pro pull --ff-only || git clone https://github.com/rune-kit/rune-pro ~/rune-pro [ -d ~/rune-business ] && git -C ~/rune-business pull --ff-only || git clone https://github.com/rune-kit/rune-business ~/rune-business ``` These repos are private, so cloning needs the user's GitHub access (an SSH key or the credential helper on the VPS). Setup finds both folders on its own. Check: in the Step 4 report, `profile.proRoot` and `profile.businessRoot` are set. ## Step 4: Start the server Pick one path. Both write the new key to `~/.rune/serve.key` (mode 0600) and **never** print it. The JSON report goes to stdout and contains no key. ### Path A: own domain → Caddy, automatic HTTPS, fixed URL Replace `rune.example.com` in every command. ```bash # A1. DNS must point here (the two IPs must match) getent ahostsv4 rune.example.com | head -1; curl -4fsS https://ifconfig.me; echo # A2. Caddy (official repo, Debian/Ubuntu; skip if `caddy version` works) sudo apt-get install -y debian-keyring debian-archive-keyring apt-transport-https curl curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --batch --yes --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list >/dev/null sudo chmod o+r /usr/share/keyrings/caddy-stable-archive-keyring.gpg /etc/apt/sources.list.d/caddy-stable.list sudo apt-get update && sudo apt-get install -y caddy # A3. Proxy the domain to Rune (added once) and reload grep -q '^rune.example.com {' /etc/caddy/Caddyfile || printf '\nrune.example.com {\n\treverse_proxy 127.0.0.1:8787\n}\n' | sudo tee -a /etc/caddy/Caddyfile >/dev/null sudo systemctl reload caddy # A4. Open the web ports (see Step 6 for the full firewall) command -v ufw >/dev/null && sudo ufw allow 80,443/tcp # A5. Start Rune rune serve setup --yes --json --expose domain --domain rune.example.com --key-out ~/.rune/serve.key ``` The Caddy block matches the `exposure.caddyfile` that setup prints. Caddy gets and renews the certificate itself, as long as ports 80 and 443 are reachable. That includes the cloud provider's firewall or security group. ### Path B: no domain → Cloudflare quick tunnel ```bash rune serve setup --yes --json --expose tunnel --key-out ~/.rune/serve.key ``` This downloads `cloudflared` into `~/.rune/bin` without root and opens no inbound ports. **The `trycloudflare.com` URL changes every time the server or VPS restarts.** After a restart, run `rune serve connect` and update each client. A domain (Path A) or a named Cloudflare tunnel gives a fixed URL. ### Check (both paths) In the JSON report, check these fields: - `ok` is `true`. - `exposure.publicUrl` is an `https://…/mcp` URL. - `health.local.reachable` and `health.public.reachable` are `true`. - `health.public.authEnforced` is `true`. Also note: - `key.file` is set only when a key was created on this run. - `health.*.handshake` is `null` unless a key is in memory. Step 6 tests the handshake. - Tell the user what is in `warnings[]` and act on `next[]`. ## Step 5: Keep it running - **systemd user session available** (most VPSes): `report.service.mode` is `systemd-user`. The unit `~/.config/systemd/user/rune-serve.service` is enabled with `Restart=on-failure`. If `next[]` contains `sudo loginctl enable-linger …`, run it. Without it, the service stops when you log out and doesn't start after a reboot. - **No systemd user session** (containers, some minimal images): `service.mode` is `background`. Add a reboot hook: ```bash (crontab -l 2>/dev/null | grep -v 'serve start'; echo "@reboot $(command -v node) $(command -v rune) serve start") | crontab - ``` Check: `rune serve status` shows `✓ server`. With systemd, `systemctl --user is-enabled rune-serve` and `systemctl --user is-active rune-serve` also print `enabled` and `active`. ## Step 6: Firewall and end-to-end check Rune listens on `127.0.0.1:8787` only. **Never open port 8787** and never pass `--host 0.0.0.0`. The proxy or tunnel is the only way in. ```bash ss -tln | grep 8787 # must show 127.0.0.1:8787, nothing else # ufw, if installed and inactive: allow SSH FIRST (use your real SSH port if it isn't 22) command -v ufw >/dev/null && { sudo ufw allow OpenSSH; sudo ufw --force enable; sudo ufw status; } RUNE_KEY="$(cat ~/.rune/serve.key)" rune serve doctor; echo "exit=$?" ``` Check: `exit=0`, and both the `local` and `public` lines show `health ✓ · auth ✓ enforced · handshake ✓ (4 tools)`. Path B needs no open web ports, Path A needs 80/443 (Step A4). If the user already moved the key to a password manager and deleted the file, run `rune serve doctor` without `RUNE_KEY`. It still checks health and auth. ## Step 7: Client config (hand this to the user) `rune serve connect all` prints a ready-to-paste block per app, with the real URL filled in and `$RUNE_KEY` in place of the key. `rune serve connect claude` prints the block for one app. Below, `https://HOST/mcp` stands for `exposure.publicUrl`. The user sets the key on their own machine first: `export RUNE_KEY=rune_sk_…` (PowerShell: `$env:RUNE_KEY = "rune_sk_…"`). | App | How | |---|---| | **Claude Code** | `claude mcp add --transport http --scope user rune https://HOST/mcp --header "Authorization: Bearer $RUNE_KEY"`, then `claude mcp list` (shows `rune: ✓ Connected`) | | **Claude Desktop / claude.ai** (custom connector) | Settings → Connectors → Add custom connector → URL `https://HOST/mcp` → Authentication **No sign in** → Request headers: `Authorization` = `Bearer `. Request headers are in beta for some organizations. **If that section is missing**, use one of the fallbacks below the table. | | **Grok via the xAI API** | Remote MCP tool in the Responses API or the xAI SDK. This is [documented by xAI](https://docs.x.ai/docs/guides/tools/remote-mcp-tools) but not yet tested against Rune. See the snippet below. | | **Grok app (grok.com)** | Unverified: we don't know whether it lets you add your own MCP servers. Use the API or another client. | | **Grok Bot** | Say: *"Add an MCP connector named rune: URL https://HOST/mcp, header Authorization: Bearer . Ask me for the key with a secure form."* | | **Grok Build, Codex, Cursor, Gemini, Antigravity, OpenCode** | Use the lines from `rune serve connect all` (also in [SERVE.md](SERVE.md#quick-start--3-steps)). OpenCode's snippet follows the installed major: `mcp.servers.rune` on OpenCode 2, flat `mcp.rune` on OpenCode 1. `rune serve connect opencode` detects `opencode --version`; `--opencode-version 1` forces the v1 shape. | | **Any other MCP client** | Streamable HTTP transport, URL `https://HOST/mcp`, header `Authorization: Bearer ` (or `X-Rune-Key: `). The server is stateless and has 4 tools: `list_skills`, `get_skill`, `get_reference`, `run_skill`. | **Claude Desktop fallback: local bridge.** The key stays in a file on the user's machine. In `claude_desktop_config.json`: ```json { "mcpServers": { "rune": { "command": "npx", "args": ["-y", "mcp-remote", "https://HOST/mcp", "--header", "X-Rune-Key:${RUNE_KEY}"], "env": { "RUNE_KEY": "rune_sk_…" } } } } ``` **claude.ai fallback: key in the URL.** This needs Rune 2.35.0 or newer (`rune --version`). On the VPS, re-run your Step 4 setup command with `--allow-query-key` added. The flag is saved: a later `rune serve setup` or `rune serve start` keeps it, and `--no-allow-query-key` turns it off. Then use the connector URL `https://HOST/mcp?key=` with **No sign in**. URLs end up in logs, so treat that URL like a password and prefer the header whenever you can. **Grok (xAI Responses API):** ```bash curl https://api.x.ai/v1/responses -H "Authorization: Bearer $XAI_API_KEY" -H "Content-Type: application/json" -d '{ "model": "grok-4.7", "input": "Use the Rune cook skill to plan adding rate limiting to my API.", "tools": [{ "type": "mcp", "server_url": "https://HOST/mcp", "server_label": "rune", "headers": { "X-Rune-Key": "'"$RUNE_KEY"'" } }] }' ``` We use the `X-Rune-Key` header here because xAI doesn't document whether its `authorization` field adds the `Bearer ` prefix, and Rune requires it in `Authorization`. In the xAI Python SDK, use `mcp(server_url=…, server_label="rune", extra_headers={"X-Rune-Key": key})`. xAI calls the server from its cloud, so it needs the public HTTPS URL. **Final message to the user** (fill it in, and don't include the key): > Rune is running on your VPS. MCP URL: `https://HOST/mcp`. Your key is in `~/.rune/serve.key` on the server. Copy it into your password manager, then delete the file (`rm ~/.rune/serve.key`). Connect: *(the lines for their apps)*. The server only serves skills, and your agent still edits code on your machine. *(Path B only: this URL changes when the server restarts; run `rune serve connect` to get the new one.)* If the user asks you to wire up a client on their machine, load the key without printing it. For example: `export RUNE_KEY="$(ssh me@host cat ~/.rune/serve.key)"`, then run the client's command in that same shell. ## Update ```bash npm i -g @rune-kit/rune@latest && rune serve start && rune serve status git -C ~/rune-pro pull --ff-only; git -C ~/rune-business pull --ff-only # if present ``` `rune serve start` restarts the server with the saved setup and keeps the key. Pro and Business pulls show up within 30 seconds, with no restart. **Path B:** the restart gives you a new URL, so run `rune serve connect` and update the clients. Check: `RUNE_KEY="$(cat ~/.rune/serve.key)" rune serve doctor` exits 0, or run it without `RUNE_KEY` if the key file is gone. ## Troubleshooting | Symptom | Fix | |---|---| | `rune: command not found` over `ssh host '…'` | Non-login shells skip your `PATH`. Use the full path: `$(npm prefix -g)/bin/rune`, or `~/.npm-global/bin/rune`. | | `setup … refuses without --yes` (exit 2) | Add `--yes`. Non-interactive shells must opt in. | | `Tunnel did not come up … never connected to the Cloudflare edge` | Outbound traffic to Cloudflare is blocked (UDP 7844 / TCP 443). Allow it, or use Path A. `rune serve start` retries. | | Doctor: `public endpoint unreachable` (Path A) | Check DNS (A1), that the Caddy block was added (A3), `sudo systemctl status caddy`, and that ports 80/443 are open in the VPS **and** the cloud firewall. Caddy logs: `journalctl -u caddy -n 50`. | | Doctor: `answered without a key` | Something bypasses Rune's auth. Make sure the proxy points at `127.0.0.1:8787` and nothing else listens publicly. | | Client gets 401 | Wrong or old key, or the `Bearer ` prefix is missing. If the key is lost, run `rune serve key rotate` (it writes the new key to `~/.rune/serve.key` without printing it) and update every client. | | Service gone after logout/reboot | `sudo loginctl enable-linger $(id -un)`, then `rune serve start`. Logs: `journalctl --user -u rune-serve -n 50`, or `~/.rune/serve.log` in background mode. | | Port 8787 already in use | Add `--port 8788` to setup, and change the Caddy block to match. | | Pro/Business skills missing | `rune serve status --json`, then look at `profile.proRoot`. Pass `--pro-root ` / `--business-root ` to setup. | ## Remove ```bash rune serve stop systemctl --user disable rune-serve 2>/dev/null; rm -f ~/.config/systemd/user/rune-serve.service npm rm -g @rune-kit/rune && rm -rf ~/.rune # Path A: delete the rune.example.com block from /etc/caddy/Caddyfile, then: sudo systemctl reload caddy ``` More detail on every flag: [SERVE.md](SERVE.md).