Source: https://www.agentweb.us/blog/how-ai-agents-handle-login-and-2fa/

# How AI agents handle login and 2FA on real websites

By Andrey Marey, Founder of AgentWeb · As of Nov 23, 2026

> **Short answer.** AI agents log into websites in one of five ways: someone hands the agent a password, the agent reuses a saved browser session, a vault types stored logins for it, a human takes over the browser at the login page, or the user signs in once on a hosted page and the agent never touches the credentials. 2FA is the part that decides which one works. Codes from an authenticator app can be automated. Text codes, push approvals and passkeys usually need the human.

## Key Takeaways

- **Never put a password in the prompt.** Browser Use's and OpenAI's docs both say so. Prompts end up in logs, traces and model context.
- **2FA splits into two groups.** Authenticator codes (TOTP) can be generated by a vault that holds the seed. Text codes, email codes, push approvals and passkeys are built to need a person or a device.
- **Saved sessions are a common fix, and expiry is their weak spot.** The agent starts signed in until the site logs it out, then the run fails or stalls.
- **Access is not approval.** A live session proves the agent can act. It does not prove the user agreed to this order, message or amount.
- **AgentWeb's approach:** a browser is used once, for a hosted sign-in. AgentWeb captures the credentials and session from that sign-in, and later requests inject them without a browser. The sign-in link expires after 15 minutes and a new one can be generated. The model never sees the secrets, and every action is scoped, permissioned and receipted.

## Why is login the hardest part of a web agent?

**Short answer:** because login is where the site checks that a real, trusted person is there. Everything an agent is bad at shows up in one place: secrets, second factors, bot checks and sessions that expire.

Clicking and typing are mostly solved. The trouble starts at the sign-in page:

1. **Secrets.** The agent needs access to the account, but anything the model sees can leak into logs, traces or a prompt injection.
2. **Second factors.** The site sends a code to a phone, asks for an app approval, or asks for a passkey. These are designed so that a password alone is not enough.
3. **Bot checks.** Some sites block or challenge automated browsers. OpenAI's own help page for its cloud browser says some websites block automated browser agents even when the same site works in your own browser.
4. **Expiry.** A session that worked yesterday can be logged out today. If nobody detects that, the agent either stops or, worse, reports success from a page that was really a login wall.
5. **Authority.** Even with a valid session, the agent still needs the user's go-ahead for things like purchases and messages.

## What are the ways an AI agent can sign in to a website?

### 1. Give the agent the password

**Short answer:** it works in a demo and fails every security review. Do not do this.

The password sits in the prompt or in an environment variable the agent can read. It ends up in logs and traces, and a prompt injection on any page can try to exfiltrate it. Browser Use's docs say "Never put passwords or TOTP secrets directly in a prompt." OpenAI's help page says "Never paste passwords, security codes, or payment details into the conversation."

### 2. Reuse a saved browser session

**Short answer:** a person signs in once, and the agent's browser reuses the cookies and storage afterwards. Browserbase, Browser Use and Anchor all document it.

Browserbase calls these contexts. Its docs recommend logging in manually once through Session Live View, then reusing the saved context so future sessions start signed in. Browser Use and Anchor call them profiles. Anchor's docs state the limit plainly: when the target site expires the session, you log in again manually, because profiles do not store credentials or re-authenticate on their own.

The tradeoff: cookies are effectively a password. You have to store them carefully, and you need a plan for when they expire.

### 3. Store the login in a vault and let it type for the agent

**Short answer:** the platform stores the username, password and sometimes a TOTP seed, and types them into the sign-in form. The agent refers to the secret by name and never sees the value.

- **Hyperbrowser Credential fill** types stored usernames, passwords and one-time codes into a login form. Values are encrypted before upload, the API never returns them, and each secret only fills on its allowed origins. It is in public preview and enabled for teams on request.
- **Steel Credentials** (beta) stores a login per site origin, with an optional TOTP secret, and fills and by default submits the form. Steel notes that code which reads the page, such as a Playwright script, can still read a filled field.
- **Browser Use** open-source secrets can be scoped to a domain, and a secret named with `bu_2fa_code` holds a TOTP seed so the agent types the current 6-digit code, never the seed. Its docs warn that the values live in the worker process, so code the model writes can read them, and that screenshots are not redacted.
- **Browserbase** documents a 1Password Agentic Autofill flow, where the user approves the login in the 1Password desktop app and the extension fills the form without returning the values to your application.

The tradeoff: this is the best option when your team owns the account. It is harder when the account belongs to each of your end users, because someone still has to collect and store their logins.

### 4. Hand the browser to a human at the login page

**Short answer:** the agent pauses, sends a live view link, the person signs in and completes 2FA, and the agent continues.

Browserbase recommends this for 2FA that cannot be disabled, using Session Live URLs. Browser Use's 2FA guide does the same with a `live_view_url` and a kept-alive browser. OpenAI's cloud browser in ChatGPT pauses at supported sign-in pages and shows a secure sign-in form. OpenAI says the username and password entered there are not visible to the model and are not stored, and the signed-in session persists for future tasks until it expires.

The tradeoff: it is the most robust answer to 2FA, but someone has to be there. It does not help an overnight job.

### 5. The user connects the account once through a hosted sign-in

**Short answer:** the user signs in on a page run by the platform, not by the agent. The platform keeps the session per account, and the agent only asks for actions.

Anchor's OmniConnect lets your end users sign in to third-party sites on Anchor's hosted UI from inside your product, and Anchor's managed authentication lists built-in MFA methods (email OTP, TOTP, 1Password and custom MFA) and re-authenticates before each session. AgentWeb also works this way, with one difference in what happens next: a browser is used only for that first sign-in, and later requests reuse the captured credentials and session without a browser. The details are in [How does AgentWeb handle sign-in?](#how-does-agentweb-handle-sign-in) below.

The tradeoff: it fits products where each end user has their own accounts. You depend on the platform supporting the sites you need.

### 6. Use the site's own API and OAuth, when it has one

**Short answer:** if the site offers an official API with OAuth, use it. OAuth 2.0 exists so a third-party app can get limited access on a user's behalf without the user's password.

Many sites do not offer an API for the tasks users want, like placing an order or booking a table. That gap is why the other five options exist. AgentWeb's own guidance says not to use it when a first-party API already provides the complete workflow.

## Sign-in options compared

| Option | Who signs in | Does the model see the secret? | 2FA | What usually breaks |
|---|---|---|---|---|
| Password in the prompt | The agent | Yes | Stuck unless the code is pasted in too | Security review, logs, prompt injection |
| Saved browser session (contexts, profiles) | A person, once | No password, but cookies sit with the browser | Done once by the person | Session expiry, then manual re-login |
| Vault fills the login (Hyperbrowser, Steel, Browser Use, 1Password) | The platform, from stored secrets | Referred to by name; caveats vary by vendor | TOTP if you store the seed | Text codes, push approvals, passkeys |
| Human takeover (live view, secure sign-in form) | A person, when asked | No | Any type, done by the person | Nobody around to respond |
| Hosted sign-in per account (Anchor OmniConnect, AgentWeb) | The end user, on the platform's page | No | Depends on the platform | Sites the platform does not support |
| Official API with OAuth | The user approves access | No password involved | Handled by the site | Most sites do not offer the needed actions |

## How do AI agents handle 2FA?

**Short answer:** it depends on the type of second factor. Authenticator app codes can be generated by software that holds the seed. Text messages, email codes, push approvals and passkeys are designed to need the person or their device, so the agent should pause and hand over.

- **Authenticator app codes (TOTP).** The code comes from a shared seed and the current time. RFC 6238, the TOTP standard, uses a default time step of 30 seconds. If a vault holds the seed, it can type a fresh code at sign-in, which is what Hyperbrowser, Steel, Browser Use and Anchor support. The tradeoff: whoever holds the seed holds the second factor, so that store now needs the same care as the password.
- **Text message and voice codes.** These go to the user's phone. NIST's digital identity guidelines (SP 800-63B-4) list out-of-band authentication over the phone network as a "restricted" authenticator. An agent cannot read them without access to that phone, so most setups hand this step to a human.
- **Email codes and magic links.** Some setups give the agent access to an inbox. NIST says email shall not be used for out-of-band authentication, though many consumer sites still send codes this way. If you read an inbox for codes, treat that inbox as a key to every account tied to it.
- **Push approvals.** "Approve on your phone" prompts need the user's device. Human takeover is the answer.
- **Passkeys.** Passkeys are built to resist phishing. Per passkeys.dev, browsers and operating systems only use a passkey for the service it belongs to, and the private key stays on the user's devices. An agent should not try to get around this. The user signs in, and the agent works from the session that results.

One more point from NIST: codes that a person types in by hand, including OTP codes, are not considered phishing-resistant, because the code is not bound to the session being authenticated. That is one reason to keep codes out of the model's reach.

## How does AgentWeb handle sign-in?

**Short answer:** the user connects each site account once through a hosted sign-in on AgentWeb's domain. AgentWeb spins up a browser for that first sign-in and captures the credentials and session from it. Later requests inject them directly, with no browser. The agent never sees them, and every action is scoped, permissioned and receipted.

AgentWeb gives an agent one MCP server or REST API to complete tasks on supported real websites, including signed-in sites with no API. Here is [the flow](https://docs.agentweb.us/agent-auth) when an action needs the user's own account on a site:

1. The agent picks a supported action and checks whether it needs an account connection, using `agentweb_connection_status`.
2. If it does, the agent calls `agentweb_start_connection` and gives the user the returned link.
3. That link is a hosted sign-in on AgentWeb's domain. It expires after 15 minutes. If it expires before the user signs in, the agent generates a new link and sends that instead.
4. For this first sign-in, AgentWeb spins up a browser so the user can sign in. AgentWeb picks up the credentials and session from that sign-in and stores them in a dedicated vault, isolated per user.
5. The agent polls `agentweb_poll_connection` until the connection is final, and stops if it is expired, refused, unavailable or attached to the wrong account.
6. Later requests reuse the captured credentials and session by injecting them into the request, without spinning up a browser. AgentWeb returns a structured result with a receipt, or a structured failure.

A note on the word "browser". AgentWeb is not a general browser agent, and that describes how tasks run after the account is connected: each one is a direct request, not a model clicking through pages. The first sign-in is the exception. It does use a browser, once, so the user can sign in on the real site.

The 15 minutes applies to the sign-in link, not to the connection. It limits how long an unused link stays valid.

What the agent never gets: the password, the cookies or the session tokens. AgentWeb's security page says the AI assistant and the model never see them. Disconnecting a site revokes the stored session immediately, and the `agentweb_disconnect` tool permanently deletes it.

The agent's own AgentWeb account works the same way. The preferred signup is a one-link flow: the agent shows the human a link, the human signs in, and the agent receives an API key. AgentWeb's docs show it uses the OAuth device authorization grant (RFC 8628), the pattern smart TVs use when they ask you to sign in on another device.

AgentWeb's docs also keep two things apart that many setups merge. A connected account shows that access exists. It does not prove the user approved this action, recipient, amount, time or account. Before a paid, irreversible or externally visible action, the agent summarizes the inputs and gets the user's approval.

The limit: AgentWeb works on mapped sites and actions. A mapped domain does not mean every workflow on that site is available. If a site is missing, the agent can request a map rather than fall back to browser automation for the task. AgentWeb has completed 510,000+ agent runs on real websites. For more, see [what a hosted login is](/glossary/hosted-login/) and [AgentWeb's security page](https://www.agentweb.us/security).

## How do you set up agent login safely?

**Short answer:** keep secrets out of the model, check the session before every signed-in task, stop on a login wall instead of guessing, and ask before anything consequential.

A checklist that works on any stack:

1. **Keep every secret out of the model.** Passwords, cookies, TOTP seeds and card numbers go in a vault or a hosted sign-in, never in a prompt, tool argument or log.
2. **Choose the sign-in owner per account.** Your team's accounts can use a vault. Your end users' accounts should use a flow where they sign in themselves.
3. **Check the session before the task, not after.** Ask "is this account connected and signed in?" first. On AgentWeb that is `agentweb_connection_status`.
4. **Treat a login wall as a failure with a reason.** If the session expired, return "not signed in" and ask the user to reconnect. Never report success from a page you did not verify.
5. **Pause for the second factors you cannot automate.** Text codes, push approvals and passkeys go to the human through a takeover link or a reconnect link.
6. **Separate access from approval.** A valid session is not consent. Confirm the item, recipient, amount and account before purchases, bookings and messages.
7. **Make risky steps safe to retry.** A retry after a timeout must not place a second order. AgentWeb's REST API deduplicates retries through an Idempotency-Key header.
8. **Give users a way out.** Users should be able to see and revoke what the agent can reach, and disconnect a site at any time.

## What about payments?

**Short answer:** treat payment as its own approval, not as part of login. The user confirms the exact total, and card numbers never enter the conversation.

AgentWeb's docs say agents must never collect raw card numbers in conversation, and that payment availability and approval requirements vary by plan, account, site and action. [AgentWeb's journal](/blog/identity-permissions-payments-and-proof/) describes checkout as running on the user's own account with the payment method saved there, after explicit approval, and says AgentWeb holds no card. We will cover agent payments in a separate post.

## When should you use something else?

AgentWeb is not the right fit for every login problem. If the site you need is not mapped yet and you cannot wait for a map, a cloud browser with a vault or human takeover will reach it sooner. If you are automating your own team's internal tools, a vault with TOTP on Browserbase, Steel, Browser Use, Anchor or Hyperbrowser may be all you need. If the site has an official API with OAuth that covers the task, use that. For a ranked view of the browser platforms, see the [best agentic browser shortlist](/best-agentic-browser/).

## Talk it through

If your agent has to act in your users' real accounts, bring the sites and the tasks. I will tell you straight whether AgentWeb covers them today, how sign-in works for each, and how to get a missing site mapped. [Book a call with me](https://cal.com/andreym/agentweb-discovery?utm_source=blog&utm_medium=organic-content&utm_campaign=how-ai-agents-handle-login-and-2fa).

Product details change, so test your exact sites and tasks before you commit. For corrections, email support@agentweb.us.

## Frequently asked questions

### Can AI agents log into websites on behalf of users?

Yes. The safe ways are a saved session the user created, a vault that types stored logins, a human takeover at the login page, or a hosted sign-in where the user connects the account once. In all of them, the model should never see the password.

### How do AI agents handle two-factor authentication?

Authenticator app codes can be generated by a vault that holds the TOTP seed. Text codes, push approvals and passkeys are designed to need the user or their device, so the agent should pause and hand the step to the human.

### Is it safe to give an AI agent my password?

Not directly. A password in a prompt ends up in logs and model context, and a prompt injection can try to steal it. Use a vault, a hosted sign-in or a human takeover so the agent can act without ever holding the password.

### What happens when the agent's session expires?

The site logs the agent out and the next task hits a login wall. A good setup checks the connection before each signed-in task and returns a clear "not signed in" failure, so the user can reconnect, instead of guessing or reporting a false success.

### Can an AI agent use passkeys?

Not on its own. Passkeys are built so they only work for the right service and the private key stays on the user's devices. The user signs in with the passkey, and the agent works from the resulting session.

### Does AgentWeb see my passwords?

Users connect site accounts through a hosted sign-in on AgentWeb's domain. A browser is used once for that sign-in, AgentWeb captures the credentials and session and vaults them per account, and later requests reuse them without a browser. The AI assistant and the model never see your password, cookies or session tokens, and disconnecting a site revokes the stored session immediately.

### Is a logged-in agent allowed to do anything in my account?

It should not be. Access and approval are separate: a connected account shows the agent can act, not that you agreed to a specific order, message or amount. Good setups ask for your approval before paid, irreversible or externally visible actions.

## Sources (accessed November 23, 2026, 10:18 to 10:22 UTC)

AgentWeb:
- One MCP server or REST API, signed-in sites with no API, pass or fail, 510,000+ agent runs, not a general browser, request a map, do not use when a first-party API covers the workflow, connection status/start/poll/disconnect tools, Idempotency-Key, approval before paid or irreversible actions, never collect raw card numbers: https://www.agentweb.us/llms.txt
- Target-site connection steps, stop if expired, refused, unavailable or wrong account, access separate from approval: https://www.agentweb.us/llms-full.txt and https://docs.agentweb.us/agent-auth.md
- Claim-link signup and OAuth device_code grant: https://docs.agentweb.us/agent-auth.md
- Hosted sign-in ceremony on AgentWeb's domain, vault isolated per user, model never sees password, cookies or session tokens, disconnect revokes immediately: https://www.agentweb.us/security
- Hosted sign-in, credentials vaulted per account, scoped, permissioned and receipted; payment approval varies: https://www.agentweb.us/ (homepage FAQ and Payments block)
- Checkout on the user's own account with saved payment method, AgentWeb holds no card: https://www.agentweb.us/blog/identity-permissions-payments-and-proof/
- Pricing custom, failed actions not billed (not quoted in body): https://www.agentweb.us/pricing and https://www.agentweb.us/pricing.md
- Hosted login definition: https://www.agentweb.us/glossary/hosted-login/
- Hosted sign-in uses a browser once, credentials / session are captured and injected into later requests without a browser, the hosted sign-in link expires after 15 minutes, a new link can be generated: confirmed by Andrey Marey, 23 Nov 2026 (founder confirmation, not a public URL).

Browserbase:
- Contexts, Session Live View login, 2FA strategies (disable or app password, remote control), 1Password Agentic Autofill: https://docs.browserbase.com/platform/identity/authentication.md
- Docs index (contexts, 1Password integration): https://docs.browserbase.com/llms.txt

Browser Use:
- 2FA guide (saved profile or human checkpoint, live_view_url, "Never put passwords or TOTP secrets directly in a prompt"): https://docs.browser-use.com/cloud/guides/2fa.md
- Open-source secrets (domain scoping, bu_2fa_code TOTP, values readable by model-written code, screenshots not redacted): https://docs.browser-use.com/open-source/secrets.md

Steel:
- Credentials (beta, origin-scoped, totpSecret, fills and submits, Playwright can read a filled field): https://steel.dev/docs/logins/credentials (fetched via https://docs.steel.dev/overview/credentials-api/overview.md)

Anchor:
- Profiles vs managed authentication, MFA methods, automatic re-auth, profiles do not re-authenticate: https://docs.anchorbrowser.io/essentials/managed-authentication.md
- OmniConnect hosted end-user sign-in: https://docs.anchorbrowser.io/essentials/omniconnect.md
- Custom MFA: https://docs.anchorbrowser.io/advanced/mfa.md

Hyperbrowser:
- Credential fill (public preview, on request, encrypted before upload, allowed origins, totp secrets): https://hyperbrowser.ai/docs/sessions/credentials.md

OpenAI:
- Cloud browser in ChatGPT (secure sign-in form, 2FA, credentials not visible to the model and not stored, session persists until it expires, some sites block agents, never paste passwords or codes): https://help.openai.com/en/articles/20001280-using-cloud-browser-in-chatgpt

Standards and guidance:
- TOTP, default 30-second time step: https://www.rfc-editor.org/rfc/rfc6238.txt
- OAuth 2.0 device authorization grant: https://www.rfc-editor.org/rfc/rfc8628.txt
- OAuth 2.0 framework (limited access on a user's behalf): https://www.rfc-editor.org/rfc/rfc6749.txt
- NIST SP 800-63B-4 (PSTN out-of-band is restricted; email shall not be used for out-of-band; manually entered OTP not phishing-resistant): https://pages.nist.gov/800-63-4/sp800-63b.html
- Passkeys (used only for the right service; private keys stay on user devices): https://passkeys.dev/docs/intro/what-are-passkeys/
