# Recipes & software factory

> Index of all pages: https://anywhere.so/llms.txt

Every recipe below runs on anywhere today using `anywhere.toml`, persistent disk storage, and optional run conventions. No orchestration framework is required. Installing the bundled CLI skill (`anywhere skill install`) also gives your local coding agent ready-to-adapt starter recipes.

## Daily error triage

Every morning at 9:00, this worker fetches yesterday's top error groups from PostHog, updates a cached git checkout on its persistent disk, asks Claude Code to investigate root causes in read-only mode, writes a self-contained HTML report (`artifacts/index.html`) plus an optional scrubbed `artifacts/transcript.jsonl`, and keeps per-error notes under `/app/data/notes/` so tomorrow's run builds on today's findings.

```toml
# triage/anywhere.toml
title = "Daily error triage"
build = "npm i -g @anthropic-ai/claude-code"

[[trigger]]
name = "triage"
cron = "0 9 * * *"
timezone = "America/New_York"
run = "REPO=owner/repo BRANCH=main POSTHOG_PROJECT=12345 bash run.sh"
timeout = 3600

[limits]
cpu = 2
memory = "6 GiB"
disk = "20 GiB"
```

Setup:

```sh
anywhere deploy ./triage
printf %s "$GITHUB_TOKEN" | anywhere secrets set --worker triage GITHUB_TOKEN
printf %s "$POSTHOG_KEY" | anywhere secrets set --worker triage POSTHOG_KEY
anywhere exec -t triage -- env CLAUDE_CONFIG_DIR=/app/data/claude claude auth login
anywhere run triage --worker triage
anywhere runs link --worker triage
```

The `run.sh` script follows **prepare -> run -> check -> note -> exit**:

- Clones `$REPO` into `/app/data/repo` on run 1, and runs `git fetch && git reset --hard` on subsequent runs.
- Queries PostHog before starting Claude, then `unset`s `GITHUB_TOKEN` and `POSTHOG_KEY` from Claude's environment so untrusted error text cannot exfiltrate credentials.
- Optionally captures `--output-format stream-json --verbose` (scrubbed of secrets) into `$ANYWHERE_RUN_DIR/artifacts/transcript.jsonl` for auditing.
- Verifies `artifacts/index.html` was produced before exiting `0`, and writes a one-line summary (`3 new errors, 4 ongoing, 2 gone`) to `$ANYWHERE_RUN_DIR/note`.

## Software factory stations

An AI software factory does not require a multi-service framework. On anywhere, a software factory is **three isolated `anywhere.toml` folders**, each on its own persistent Linux disk with least-privilege secrets and a human reviewing what merges:

1. **Station 1 — Morning triage (`triage`):** `0 9 * * *` with Claude Code. Investigates production errors and failed CI, writes an HTML evidence report, and saves notes across days in `/app/data/notes/`.
2. **Station 2 — PR & issue review (`pr-review`):** Webhook `[[trigger]]` with `dedupe_header = "x-github-delivery"` triggered by GitHub pull request or Linear issue webhooks using Codex. Verifies HMAC signatures from `ANYWHERE_WEBHOOK_HEADERS`, updates the cached repo on disk, runs tests, and posts concrete findings.
3. **Station 3 — Weekly maintenance (`cleanup`):** `0 8 * * 1` with Claude Code or Codex. Checks documentation drift, outdated dependencies, and stale flags, then opens a draft PR for human merge.

```toml
# pr-review/anywhere.toml
title = "PR reviewer"
build = "npm i -g @openai/codex"

[[trigger]]
name = "on-pr"
webhook = true
dedupe_header = "x-github-delivery"
run = "bash review.sh"
timeout = 1200

[limits]
cpu = 2
memory = "4 GiB"
disk = "20 GiB"
```

Because each station has its own gVisor sandbox, its own scoped token, and its own persistent disk, a busy PR webhook burst never blocks morning triage and a read-only reviewer never holds merge credentials.

## Webhook responder

Point GitHub, Linear, Stripe, or Datadog webhooks at a secret trigger URL. Incoming payloads arrive byte for byte on `stdin` with headers in `ANYWHERE_WEBHOOK_HEADERS`, duplicate retries are absorbed by `dedupe_header`, and bursts queue serially up to 100 deep so nothing is dropped.

```toml
# issue-responder/anywhere.toml
title = "Issue responder"
build = "npm ci && npm run build"

[[trigger]]
name = "on-issue"
webhook = true
dedupe_header = "x-github-delivery"
run = "node dist/on-issue.js"
timeout = 600
```

```ts
// issue-responder/src/on-issue.ts
import { createHmac, timingSafeEqual } from "node:crypto";
import { readFileSync, writeFileSync } from "node:fs";

const raw = readFileSync(0, "utf8");
const headers = JSON.parse(process.env.ANYWHERE_WEBHOOK_HEADERS ?? "{}");
const sig = headers["x-hub-signature-256"] ?? "";
const expected =
  "sha256=" +
  createHmac("sha256", process.env.WEBHOOK_SECRET ?? "")
    .update(raw)
    .digest("hex");

if (
  sig.length !== expected.length ||
  !timingSafeEqual(Buffer.from(sig), Buffer.from(expected))
) {
  writeFileSync(
    `${process.env.ANYWHERE_RUN_DIR}/note`,
    "Invalid webhook signature\n",
  );
  process.exit(1);
}

const payload = JSON.parse(raw);
// Run your agent or script, write artifacts, and leave a one-line note.
writeFileSync(
  `${process.env.ANYWHERE_RUN_DIR}/note`,
  `Handled issue #${payload.issue?.number ?? "unknown"}\n`,
);
```

Deploy, generate the webhook URL, test locally with a sample payload, and replay any past run after a fix:

```sh
anywhere deploy ./issue-responder
printf %s "$WEBHOOK_SECRET" | anywhere secrets set --worker issue-responder WEBHOOK_SECRET
anywhere triggers url on-issue --worker issue-responder

# Test locally with a sample JSON body on stdin
anywhere run on-issue --worker issue-responder < sample-issue.json

# Inspect or replay a past run with its kept input after deploying a fix
anywhere runs input RUN_ID --headers --worker issue-responder
anywhere runs replay RUN_ID --worker issue-responder
```

## Weekly research digest

Run a scheduled Python or TypeScript agent against OpenRouter or any model provider, accumulate historical snapshots in SQLite at `/app/data/history.db`, and write a clean HTML digest to `$ANYWHERE_RUN_DIR/artifacts/index.html`:

```toml
# digest/anywhere.toml
title = "Weekly research digest"
build = "python3 -m venv /app/.venv && /app/.venv/bin/pip install -r requirements.txt"

[[trigger]]
name = "weekly"
cron = "0 8 * * 1"
timezone = "Europe/London"
run = "/app/.venv/bin/python digest.py"
timeout = 900

[limits]
cpu = 1
memory = "2 GiB"
disk = "10 GiB"
```

Because `/app/data/history.db` persists across weeks, each Monday's run diffs new findings against prior snapshots instead of starting from scratch, and sleeps at `$0` compute for the other 167 hours of the week.

## Agent with local and remote MCP servers (`mcp-agent`)

An agent worker can use both local MCP servers (stdio or `127.0.0.1` HTTP on any port except `7682`) and remote HTTPS MCP servers authenticated with encrypted worker secrets:

```toml
# mcp-agent/anywhere.toml
title = "MCP ops analyst"
build = "npm i -g @anthropic-ai/claude-code && npm ci"

[[trigger]]
name = "daily-check"
cron = "0 10 * * 1-5"
timezone = "UTC"
run = "bash run.sh"
timeout = 1200

[limits]
cpu = 2
memory = "4 GiB"
disk = "10 GiB"
```

```json
{
  "mcpServers": {
    "local-sqlite": {
      "command": "node",
      "args": ["/app/node_modules/.bin/mcp-sqlite", "/app/data/metrics.db"]
    },
    "linear": {
      "type": "http",
      "url": "https://mcp.linear.app/mcp",
      "headers": {
        "Authorization": "Bearer ${LINEAR_API_KEY}"
      }
    }
  }
}
```

```sh
#!/bin/sh
# mcp-agent/run.sh
set -eu

mkdir -p "$ANYWHERE_RUN_DIR/artifacts"

# Keep external MCP data isolated from shell tools and unrelated secrets:
# allow only the declared MCP tools, write the raw stream outside artifacts/,
# then scrub secrets and bound its size before copying into artifacts/.
claude -p "$(cat prompt.md)" \
  --mcp-config /app/.mcp.json \
  --strict-mcp-config \
  --tools "" \
  --allowedTools "mcp__local-sqlite__*,mcp__linear__*" \
  --permission-mode dontAsk \
  --output-format stream-json --verbose \
  </dev/null > "$ANYWHERE_RUN_DIR/claude.jsonl"

python3 /app/transcript.py "$ANYWHERE_RUN_DIR/claude.jsonl" \
  "$ANYWHERE_RUN_DIR/artifacts/transcript.jsonl"
python3 /app/render_report.py "$ANYWHERE_RUN_DIR/claude.jsonl" \
  "$ANYWHERE_RUN_DIR/artifacts/index.html"

test -s "$ANYWHERE_RUN_DIR/artifacts/index.html"
python3 -c 'import json, sys; print([json.loads(l) for l in sys.stdin][-1]["result"].strip().splitlines()[0][:200])' < "$ANYWHERE_RUN_DIR/claude.jsonl" > "$ANYWHERE_RUN_DIR/note"
```

Set the secrets (`anywhere secrets set --env-file .env --worker mcp-agent`), deploy, and verify with `anywhere run daily-check --worker mcp-agent`. Because nothing outside the worker can reach its local MCP servers, credentials and local databases stay walled inside the sandbox.

## Headless browser agent (`browser-agent`)

Every run wakes the worker, starts headless Chromium inside the sandbox through `agent-browser`'s built-in stdio MCP server (`recipes/browser-agent/` in the Anywhere skill), carries out one browser task, saves screenshots and `report.md` into `$ANYWHERE_RUN_DIR/artifacts/` (while the harness keeps its own session history on `/app/data/`), shuts Chromium down cleanly, and lets the worker go straight back to sleep. The bundled starter uses Claude Code, and the same pattern works with any harness or script.

```toml
# browser-agent/anywhere.toml
title = "Claude with a headless browser"
build = "bash setup.sh"

[[trigger]]
name = "check"
cron = "0 8 * * *"
run = "exec env TARGET_URL=https://example.com TASK='Summarize the page and capture a screenshot.' bash run.sh"
timeout = 1800

[limits]
cpu = 1
memory = "2 GiB"
disk = "5 GiB"
```

Setup:

```sh
anywhere deploy ./browser-agent
anywhere exec -t browser-agent -- env CLAUDE_CONFIG_DIR=/app/data/claude claude auth login
anywhere run check --worker browser-agent </dev/null
anywhere runs link --worker browser-agent
```

Key design choices for headless browsers inside gVisor:

- **No exposed CDP port:** the browser runs solely inside the worker's trigger runs and closes via `agent-browser close --all` on exit and `SIGTERM` (before the 10 s `SIGKILL`), so persistent profiles flush cleanly and the sandbox sleeps immediately.
- **Least-privilege MCP tooling & Chromium URL policy:** `mcp.json` launches `check.py proxy` → `agent-browser mcp --tools core --config <trusted-config>` through `env -i` to keep worker secrets out of Chromium's environment, while Claude runs with `--tools ""` and only allowlisted `mcp__browser__*` tools (`agent_browser_eval`, `agent_browser_flow_*`, `extraArgs`, and arbitrary screenshot `path`/`screenshotDir` arguments are blocked). Both the proxy and a Chromium managed `URLBlocklist`/`URLAllowlist` policy pin navigation to `ALLOWED_DOMAINS` (defaulting to `TARGET_URL`'s host), blocking `file://`, `chrome://`, and off-domain URLs in both ephemeral and persistent-profile modes. Before keeping `report.md` or screenshots, `run.sh` screens Claude's output and report for the worker's secrets and sign-in tokens and fails closed on a hit.
- **gVisor and egress flags:** the generated config sets `--disable-quic` (avoiding UDP/443 probes that DNS-only egress drops), `--disable-gpu`, nonce `contentBoundaries: true` and `maxOutput: 40000`, and `/dev/shm` scales to half the sandbox's memory limit.
- **Pinned builds and persistent state:** `setup.sh` installs pinned Claude Code, `agent-browser`, Ubuntu system libraries, CJK/emoji fonts, and a SHA256-verified Chrome for Testing archive onto the persistent ZFS disk once and skips already-verified parts on later deploys. Set `PERSIST_PROFILE=1` to keep cookies and `localStorage` under `/app/data/browser-profile` (with `flock` locking and automatic stale `Singleton*` lock cleanup), and optionally `ALLOWED_DOMAINS` to pin navigation to expected hosts. Raise `[limits]` to `cpu = 2` and `memory = "4 GiB"` on Pro for heavier multi-tab SPAs.
