Developer & AIvendor:githubEmail OTPUnwrapped Magic LinkCarrier SMS DIDCloud KMS TOTP
Automate GitHub 2FA, Device Verification & TOTP in Playwright & Stagehand
Automate GitHub device verification OTPs, confirm-email magic links, SMS fallback codes, and Cloud KMS TOTP in Playwright, Stagehand, and Browser Use.
1. 60-Second Gmail & Outlook Auto-Forwarding Filter
Don't want to change your existing account email on GitHub? Keep your corporate inbox on GitHub and forward only verification emails to <identity-slug>@in.sentryrelay.com. Sentry Relay's Stage 2 unwrapper preserves the original GitHub sender header automatically (full setup guide).
# Paste into Gmail -> Settings -> Filters -> Create a new filter ("Has the words")
from:(noreply@github.com) ("verification code" OR "verify your device" OR "launch code" OR "sudo")
# Action: Forward it to -> <your-identity-slug>@in.sentryrelay.com2. Copy-Paste GitHub 2FA Automation Snippets
Choose your browser automation stack below. All snippets resolve codes in <200ms with Upstash Redis 15-second lookback protection so arrived-before-wait race conditions never fail a run.
import { test, expect } from '@playwright/test';
import { SentryRelay } from '@sentryrelay/sdk';
const relay = new SentryRelay({ apiKey: process.env.SENTRY_RELAY_API_KEY! });
test('GitHub login with TOTP + new-device Email OTP fallback', async ({ page }) => {
await page.goto('https://github.com/login');
await page.fill('input#login_field', process.env.GITHUB_USERNAME!);
await page.fill('input#password', process.env.GITHUB_PASSWORD!);
await page.click('input[type="submit"]');
// Path A: Vaulted RFC 6238 TOTP (auto-waits <=4s if window is expiring)
const totpInput = page.locator('input#app_totp');
if (await totpInput.isVisible({ timeout: 4000 }).catch(() => false)) {
const token = await relay.totp.get('github-runner', 'github_ops');
await totpInput.fill(token.code);
}
// Path B: Unrecognized cloud runner IP triggers GitHub Device Verification
const deviceInput = page.locator('input#otp');
if (await deviceInput.isVisible({ timeout: 4000 }).catch(() => false)) {
const auth = await relay.wait('github-runner', {
channel: 'email',
sender: 'github.com',
timeout: 30,
});
if (auth.event?.otpCode) {
await deviceInput.fill(auth.event.otpCode);
} else if (auth.event?.magicLink) {
await page.goto(auth.event.magicLink);
}
}
await expect(page).toHaveURL(/github\.com/);
});3. GitHub Production Gotchas
Cloud IPs Trigger Device Verification Even With Valid TOTP
When GitHub sees a fresh Browserbase, Cloud Run, or GitHub Actions runner IP, it often triggers a 6-digit "Device verification" email even when TOTP is configured. Always handle both TOTP and Email OTP fallback.
Repo Notification Noise Pollutes Naive Regex Pollers
If your bot account watches active repositories, issue #123456 or commit SHAs look like 6-digit codes to naive regexes. Stage 4 explicitly disqualifies PR, issue, Dependabot, and release emails before extraction.
Sudo Mode Prompts Mid-Session
Navigating to organization settings or token creation triggers GitHub sudo mode. Query `relay.totp.get()` (with automatic <=4s rollover protection) or `relay.wait()` with `sender: "github.com"` right after clicking the sudo prompt.