← All articles

How to Handle 2FA in an AI Agent Without Breaking Security

TL;DR

2FA exists to stop exactly what an autonomous agent is doing, so it cannot and should not be automated away. The pattern that works is a live handoff: the agent detects the second-factor prompt, a person approves it on their own device or types the code into the agent's live browser, and the session persists so it is not asked again for a long time. Never disable 2FA for an agent account and never put TOTP seeds in a prompt.

Two-factor authentication is working as intended when it stops your agent. The goal is not to defeat it. The goal is to let the right human answer it, in the agent's session, quickly, and then not be asked again for weeks.

The two bad answers

Turning 2FA off for the agent account removes the protection from an account that now acts autonomously across many sites, which is the account that needs it most. Putting the TOTP seed in the agent's configuration means the second factor now lives next to the first one, so it is no longer a second factor, and it sits in a prompt that ends up in logs.

The answer that keeps 2FA intact

The agent recognises the second-factor prompt and stops. A person is notified with a link to the agent's live browser. They approve the push on their own phone, or type the code into the field they can see, in the agent's session. The site marks the browser as trusted, usually for thirty days, and the agent carries on. The human spent fifteen seconds and the secret never left their device.

Make it happen less

Most of the pain is repeated prompts, and most repeated prompts come from throwing the browser profile away. Persist the profile per agent so the trusted-device cookie survives. One human approval a month per site is a cost any team accepts; one per run is not.

if page_asks_for_second_factor(page):
    # A person approves on their own phone or types the code into this browser.
    fix = oo.request_fix(url=page.url, task="approve the sign-in second factor")
    wait_for(fix)
    # The profile now holds the trusted-device cookie; this prompt should not return for weeks.

A recorded fix here is deliberately thin. The procedure that gets learned is where the prompt appears and what to press afterwards. The code itself is never captured, because a fix session is exactly where codes get typed.

Questions people ask

Can an AI agent handle two-factor authentication?

Not on its own, and it should not. The agent detects the prompt and hands it to a person who approves on their own device or types the code into the agent's live browser. The session then stays trusted.

Should I disable 2FA on the account my agent uses?

No. That account acts autonomously across many sites and is the one that most needs the protection. Keep 2FA and persist the trusted-device session instead.

Can I give the agent the TOTP secret?

You can, but the second factor then lives beside the first, which defeats it, and the seed sits in configuration that reaches logs. A live human approval is safer and rarely needed once the browser is trusted.

How often will a human be needed for 2FA?

With a persistent browser profile, typically once per site per trusted-device window, often thirty days. Without one, every run.

DoubleOh is the reliability layer for AI agents. When one gets stuck, a person fixes it once in a live browser, and the fix becomes a skill the whole fleet follows from then on.

Start free