The overnight agent-QA setup: guardrails, Sentry MCP, run template
The short version
An AI agent runs against the app overnight across three devices. It operates under fixed constraints: read-only access to real data, no destructive actions, and any cleanup it wants to perform is written to a file for a human to review rather than executed.
In one night it found the real performance number (which contradicted the assumption), a failure rate nobody knew about, and internal documentation that no longer matched what was actually running. Constraints first, autonomy second.
Copy these prompts
Paste them into Claude Code (or any AI that can see your project), in this order. Each one answers a different question, and the first is usually the one that matters.
1. It can look, it cannot touch
I want an AI agent to test my app unattended overnight. Set it up with read-only access to real data, and show me exactly how that restriction is enforced rather than just requested.
2. Cleanup gets written down, not done
Make any cleanup or repair the agent wants to perform get written to a file for me to review in the morning instead of being executed. Show me what that file should contain so I can act on it quickly.
3. Give it a list it may never cross
Write the explicit list of actions this agent may never take, and tell me how I would notice if it ever tried. I want to see the attempt, not just trust that it did not happen.
An AI tested my app on three phones while I slept, and found what I couldn't. The night it earned its keep, a Claude agent connected to Sentry found the REAL p50 (4.4s; my guess was wrong), a 31% failure rate I didn't know existed, and my own docs lying about which model runs in prod. The order matters: guardrails first, then autonomy.
The guardrails (set these BEFORE the first run)
- Read-only database access. The QA agent gets a read-only DB role/connection string. It can inspect anything, mutate nothing:
CREATE ROLE qa_agent LOGIN PASSWORD '...' ;
GRANT CONNECT ON DATABASE app TO qa_agent;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO qa_agent; -- and nothing else
- No destructive ops, structurally. Not "please don't delete" in the prompt: the permissions make it impossible. Prompts are wishes; grants are guarantees.
- Cleanup is written, never executed. If the agent's testing creates data (test users, test
expenses), it writes the cleanup as a reviewed file (
cleanup-2026-07-12.sql) that YOU run after reading it. The agent never runs its own deletes. - Real observability access via MCP. Wire the Sentry MCP server (or your APM's) so the agent queries actual traces, error rates, and percentiles instead of guessing from logs. This is where every real finding came from.
The run template
- Give it missions, not vibes. My overnight prompt structure:
MISSION: overnight QA of <app> against production.
YOU MAY: exercise user flows on the test devices/simulators, query Sentry
(traces, issues, p50/p95 by endpoint), read the DB (read-only), read the repo.
YOU MAY NOT: mutate data, change config, execute cleanup.
DELIVER: findings ranked by severity, each with EVIDENCE (trace link, query,
repro steps), a claimed-vs-observed section, and cleanup as a file.
- Include a "claims vs reality" pass. Explicitly ask: compare docs/marketing claims against observed behavior. That instruction is what caught my docs claiming a different AI model than the one in prod traces.
- Demand evidence per finding. No finding without a trace ID, SQL result, or repro. This turns "the agent thinks something's wrong" into a triage-able report.
- Review in the morning like a PR. Findings ranked, evidence attached, cleanup file read before running. The agent found the 31%; deciding what to do about it stayed human.
Driving the devices
The guardrails above are what the agent may not do. This is how it actually touches the app — the part that turns "go test my app" into every button on three devices with a screenshot either side.
Android — adb can do the whole loop
adb devices -l # confirm the emulator is up
adb install -r app-debug.apk
adb shell am start -n com.example.app/.MainActivity
adb shell uiautomator dump /sdcard/ui.xml # the view hierarchy, with bounds
adb pull /sdcard/ui.xml . # every clickable node and its rect
adb shell input tap 540 1200 # centre of a node's bounds
adb shell input swipe 540 1600 540 600 300 # scroll
adb shell input text "hello"
adb exec-out screencap -p > step-04.png # straight to a file, no /sdcard round trip
adb shell screenrecord --time-limit 30 /sdcard/run.mp4
adb logcat -d > step-04.log # what the app said while you did it
uiautomator dump is the piece that makes it autonomous: it returns every node with
clickable="true" and its bounds, so the agent enumerates the real controls on the current screen
rather than guessing coordinates. Tap the centre of each rect, screenshot before and after, diff.
iOS — simctl boots and captures, but it cannot tap
xcrun simctl list devices available
xcrun simctl boot "iPhone 15 Pro"
xcrun simctl install booted MyApp.app
xcrun simctl launch booted com.example.app
xcrun simctl io booted screenshot step-04.png
xcrun simctl io booted recordVideo run.mov
xcrun simctl spawn booted log stream --level debug > run.log &
simctl has no tap command. For synthetic touches you need either
idb (brew tap facebook/fb && brew install idb-companion):
idb ui describe-all --udid $UDID # the accessibility tree — labels, frames
idb ui tap 180 420 --udid $UDID
idb ui swipe 180 600 180 200 --udid $UDID
idb ui text "hello" --udid $UDID
…or an XCUITest target driven by xcodebuild test, which is heavier but needs no extra dependency
and runs the app's own accessibility identifiers.
idb ui describe-all is the iOS equivalent of uiautomator dump: it names every element with a
frame, so the same enumerate-tap-capture loop works on both platforms.
The loop the agent runs
For each device, for each screen:
- Dump the hierarchy (
uiautomator dump/idb ui describe-all). - Enumerate every interactive node with its rect. Skip anything already visited this run — keep a set of screen-hash + node-id or it will walk in circles.
- Screenshot, tap the node centre, wait for idle, screenshot again.
- Record what happened: the node's label, the two screenshots, the log tail, and whether the screen changed. A tap that changes nothing is worth flagging.
- Back out (
adb shell input keyevent 4/ a back tap) and continue.
Everything lands in one run directory per device — runs/2026-09-09/iphone-15-pro/ — so the morning
review is a folder, not a transcript.
What this must NOT be allowed to do
The rules at the top still bind here, and the device layer adds one more: never point it at a
device signed into a real account. Use a simulator with a seeded test user. adb and idb will
happily tap "Delete account" — that is a real button, and an agent enumerating every control will
find it. Keep the never-do list in front of it, and prefer a build where destructive actions are
feature-flagged off.
Steal this for your app
- Agents don't get bored at 3 a.m. Use them for the QA humans never sustain: full-flow sweeps, percentile checks, claim audits, every night.
- The guardrail trio (read-only creds, structural no-destructive, write-don't-execute cleanup) transfers to ANY agent you give production access. Autonomy is earned per-capability, not granted globally.
- Your first overnight run will disprove at least one number you were confident about. Mine was the p50; I was wrong by seconds.
Run this on your codebase
Paste this into Claude Code in your repo:
Audit this repo's readiness for overnight agent QA.
Check database roles and connection strings available to agents or CI; flag any credential with write or delete grants that a QA process could pick up.
Search for agent or automation prompts that rely on "do not delete" wording instead of structural permissions.
Check whether test-data cleanup exists as reviewed script files rather than commands an agent executes itself.
Check for observability access (Sentry, APM, trace APIs) an agent could query for real p50/p95 and error rates.
List documented claims in README or docs about models, latency, or reliability that could be verified against production traces.
Report findings as a checklist before changing anything.