Repository Public
1# SP Wallet research runner23A small standalone service for a **research node** — a machine that is neither the wallet API's nor the signer's. It4pulls research jobs from the wallet API, runs an AI coding agent on each inside an OS sandbox, enforces the owner's5budgets from outside, and pushes back a log and one result. Design and threat model: `docs/v7/RESEARCH-RUNTIME.md`.67It holds: its own shared secret, the API's URL, a laboratory checkout, and a model credential. It never holds a wallet8secret, a database URL or the signer's address, and refuses to start if `DATABASE_URL`, `RESEARCH_DATABASE_URL`,9`SPW_SIGNER_*`, `SPW_ORIGIN` or `SPW_RP_ID` are in its environment.1011## Install on a research node (macOS)1213```bash14# 1. a SPARSE checkout: the laboratory only — the application code is not on this machine15git clone --filter=blob:none --no-checkout gitsrv:srv/git/sp-wallet.git ~/sp-wallet-lab && cd ~/sp-wallet-lab16git sparse-checkout set research && git checkout main17cd research && uv sync --frozen # the laboratory's Python environment (read-only for jobs)1819# 2. the runner bundle (built from the same commit on a build machine: node scripts/build.mjs → dist/research-runner.mjs)20mkdir -p ~/sp-wallet-research && cp research-runner.mjs ~/sp-wallet-research/2122# 3. the coding agent23npm install -g @anthropic-ai/claude-code # /opt/homebrew/bin/claude24```2526Environment (PM2 / launchd; a file readable by the service user only):2728| Variable | Meaning |29|---|---|30| `SPW_RUNNER_API_URL` | the wallet API, e.g. `https://wallet.example` |31| `SPW_RUNNER_SECRET` | the same value as the API's `SPW_RESEARCH_RUNNER_SECRET` (≥ 32 characters, used for nothing else) |32| `SPW_RUNNER_LAB_DIR` | `~/sp-wallet-lab/research` |33| `ANTHROPIC_API_KEY` | a **dedicated** model key for research (or `CLAUDE_CODE_OAUTH_TOKEN`). Read once, removed from the environment, given to the per-job gateway. Jobs never see it. |34| `SPW_RUNNER_HOME` | default `~/sp-wallet-research` (`jobs/`, `state/`); must not be inside a checkout |35| `SPW_RUNNER_ID`, `SPW_RUNNER_MODEL`, `SPW_RUNNER_CLAUDE_BIN`, `SPW_RUNNER_POLL_MS` | optional |36| `SPW_RUNNER_LAB_PIN` | `commit` (default: `git archive` of the job's pinned commit; `git fetch` it first) or `worktree` (development) |37| `SPW_RUNNER_SANDBOX` | `off` only on a platform without `sandbox-exec`; every result then says `sandbox: none` |3839Run: `node ~/sp-wallet-research/research-runner.mjs`. A draft manifest for the cluster's deployment tool is in40`deploy/research-runner.manifest.draft.json` (to be adapted to the tool's schema; it has no secret in it).4142After a laboratory update: `git -C ~/sp-wallet-lab pull && (cd ~/sp-wallet-lab/research && uv sync --frozen)`. A job43pinned to a commit whose `uv.lock` differs from the environment is refused, not run.4445## What a job looks like on disk4647```48~/sp-wallet-research/jobs/<id>/ro/ lab/ (src, schema, strategies as examples) data/ JOB.json CLAUDE.md read-only49~/sp-wallet-research/jobs/<id>/rw/ work/ (cwd) work/submission/ ledger/trials.jsonl tmp/ home/ read-write50~/sp-wallet-research/state/<id>/ ledger.jsonl (append-only copy) profile.sb runner only51```52The job directory is removed when the job ends (`SPW_RUNNER_KEEP_JOBS=1` keeps it); `state/` stays.5354## Tests5556`npx vitest run services/research-runner` — the state machine with the fake agent (`test/fixtures/fake-agent.mjs`),57the sandbox denials (macOS), the gateway against a fake model API. No model call, no network.58