How to let an AI agent complete sign-up, login and 2FA on your own app

Last updated 2026-12-03 · By the Humanless team at Ninety Nine Oranges · Markdown version

Short answer: Give the agent two tools: one that creates a fresh email address, phone number or TOTP secret, and one that blocks until the verification code arrives and returns it already parsed. Don't let the model guess codes, loop on screenshots of a webmail tab, or wait for a human. In Claude Code, Claude Desktop or Cursor, connect the Humanless remote MCP server (https://api.usehumanless.com/mcp). In browser-use, Stagehand or your own agent loop, call the same four operations over REST from a custom tool. Use it only on apps you own or are authorized to test.

Use policy: Humanless is for agents and tests working on your own products or apps you are explicitly authorized to test. Don't point an agent at third-party sign-ups, trials or verification checks. That breaks our Terms, and usually theirs too.

Why agents get stuck at "Enter the code we sent you"

A browser agent can fill a sign-up form, but the next step needs something outside the browser: an inbox, a phone, or an authenticator app. Without a tool for that, agents tend to do one of four things: stop and ask a human, open a webmail tab and try to read it from screenshots, invent a code, or give up. All four break unattended runs.

Your options

OptionGood forTrade-off
Hand off to a human (live view, Slack ping)Rare, high-stakes loginsNot unattended. The run waits on a person.
Reuse a logged-in session (Playwright storageState, a saved browser profile)Agents that only need to be logged inDoesn't test sign-up or 2FA. Sessions expire.
Test-mode bypass in your app (fixed OTP for allowlisted test accounts, e.g. Firebase Auth's fictional test phone numbers)Fast, deterministic checksSkips the real email or SMS path.
Give the agent the TOTP secret and a code generatorAccounts protected only by an authenticator appNeeds the secret stored safely. No email or SMS.
Inbox and number tools (MCP or REST)Sign-up, email OTP, magic links, SMS, TOTP, end to endA service dependency. SMS costs money.

Pick the cheapest one that covers what you need to test. If the agent's job is "sign up like a new user and get to the dashboard", you need the last option.

Option A: Claude Code, Claude Desktop or Cursor via MCP

Humanless is a remote MCP server: Streamable HTTP, stateless, authenticated with the same Bearer hl_live_... API key as the REST API. Nothing runs locally.

Claude Code
claude mcp add --transport http humanless https://api.usehumanless.com/mcp \
  --header "Authorization: Bearer hl_live_YOUR_KEY"
Cursor: ~/.cursor/mcp.json
{
  "mcpServers": {
    "humanless": {
      "url": "https://api.usehumanless.com/mcp",
      "headers": { "Authorization": "Bearer hl_live_YOUR_KEY" }
    }
  }
}

Claude Desktop only launches local (stdio) servers from its config file, so bridge with mcp-remote. The header goes through an env var because some platforms mangle spaces inside args:

claude_desktop_config.json
{
  "mcpServers": {
    "humanless": {
      "command": "npx",
      "args": ["-y", "mcp-remote", "https://api.usehumanless.com/mcp",
               "--header", "Authorization:${HUMANLESS_AUTH}"],
      "env": { "HUMANLESS_AUTH": "Bearer hl_live_YOUR_KEY" }
    }
  }
}

The four tools

ToolArgumentsReturns
create_verification_identitychannels: any of email, sms, totp (default ["email"]), ttl_seconds?, domain?identity_id, email, phone (E.164), totp_secret (base32), expires_at
wait_for_verification_codeidentity_id, channel? (any/email/sms), timeout_seconds? (default 30, max 60), since_unix_ms?Text starting OTP: 482913 and/or Magic link: https://.... A timeout is a normal result, not an error: call again.
get_totp_codeidentity_id{ code, seconds_remaining }
delete_verification_identityidentity_id{ identity_id, status: "deleted" }. Safe to call twice.

Full parameter and error reference: MCP docs and REST API reference.

Errors come back as tool results with isError: true and a hint telling the agent what to do next. For example, payment_required means SMS needs a paid plan or credits, so use email. identity_ended means the identity expired, so create a new one.

A prompt that works

prompt
Open http://localhost:3000/signup and create an account.
Use create_verification_identity with channels ["email"] for the email address.
After submitting, call wait_for_verification_code (don't sleep first) and enter the code.
Then turn on 2FA in Settings → Security and finish enrollment.
When you are done, call delete_verification_identity.

The agent's flow is always the same: create → type the email/phone into the form → submit → wait → enter the code or open the link → delete. Each message is delivered once. To be safe against a code that arrives before the wait starts, the agent can pass since_unix_ms set just before it submitted the form.

Option B: browser-use, Stagehand or your own agent loop via REST

Every MCP tool has a REST equivalent at https://api.usehumanless.com/v1. Wrap them as functions and register them with whatever tool or function-calling mechanism your framework uses (custom actions, tools, LangChain tools, OpenAI or Anthropic function calling):

humanless_tools.py
import os
import requests

API = "https://api.usehumanless.com/v1"
H = {"Authorization": f"Bearer {os.environ['HUMANLESS_API_KEY']}"}


def create_identity(channels: list[str] = ["email"]) -> dict:
    """Create a disposable email / phone / TOTP identity. Returns identity_id, email, phone, totp_secret."""
    r = requests.post(f"{API}/identities", headers=H, json={"channels": channels}, timeout=15)
    r.raise_for_status()
    return r.json()


def wait_for_code(identity_id: str, channel: str = "any", since_ms: int | None = None) -> dict:
    """Block (up to 60 s) until the next email/SMS arrives. Returns code and/or magic-link url."""
    params = {"channel": channel, "timeout": 60}
    if since_ms is not None:
        params["since"] = since_ms
    r = requests.get(f"{API}/identities/{identity_id}/wait", headers=H, params=params, timeout=75)
    if r.status_code == 408:  # nothing yet: not an error, just call again
        return {"status": "timeout"}
    r.raise_for_status()
    m = r.json()
    return {"status": "received", "code": m["code"], "url": m["url"], "snippet": m["raw_snippet"]}


def get_totp(identity_id: str) -> dict:
    """Current 6-digit TOTP code and seconds_remaining for an identity created with 'totp'."""
    r = requests.get(f"{API}/identities/{identity_id}/totp", headers=H, timeout=15)
    r.raise_for_status()
    return r.json()


def delete_identity(identity_id: str) -> None:
    requests.delete(f"{API}/identities/{identity_id}", headers=H, timeout=15).raise_for_status()

In TypeScript, mix deterministic code with AI steps. Here the agent handles the UI and your code handles the code. This uses the Humanless SDK with Stagehand's act():

agent-signup.ts
import { Humanless, withIdentity } from "./humanless"; // TypeScript SDK, one file: usehumanless.com/sdk/humanless.ts

const hl = new Humanless({ apiKey: process.env.HUMANLESS_API_KEY! });

await withIdentity(hl, { channels: ["email"] }, async ({ identity_id, email }) => {
  const sentAt = Date.now();
  await stagehand.act(`sign up on the page using the email ${email} and submit the form`);
  const { code } = await hl.waitForCode({ identityId: identity_id, since: sentAt });
  await stagehand.act(`enter the verification code ${code} and continue`);
});

Prefer this split when you can. The model never has to read the email, so it can't misread or leak it.

Safety rules for agents with verification tools

FAQ

How can an AI agent handle 2FA or OTP codes?

Give it a tool that receives the code. For email and SMS, use a disposable inbox or number with a blocking "wait for code" call. For authenticator apps, give it the TOTP secret and a code generator. Humanless provides all three as MCP tools (create_verification_identity, wait_for_verification_code, get_totp_code) and as REST endpoints.

Is there an MCP server for receiving email verification codes?

Yes. Humanless runs a remote MCP server at https://api.usehumanless.com/mcp (Streamable HTTP, Bearer API key) with four tools for creating identities, waiting for codes or magic links, getting TOTP codes and deleting identities. It works with Claude Code, Cursor, Claude Desktop (through mcp-remote) and any MCP client that supports Streamable HTTP and custom headers.

Can Claude or Cursor sign up for a website on its own?

For your own app or one you're authorized to test, yes. Connect a verification MCP server and a browser tool, and the agent can fill the form, wait for the code and finish the flow. Don't use this to create accounts on third-party services. Humanless's Terms prohibit it.

How do I give browser-use or Stagehand an email inbox?

Wrap the Humanless REST calls (POST /v1/identities, GET /v1/identities/:id/wait) as a custom tool or action. Or keep the wait in your own code and pass the code to the agent, as in the Stagehand example above.

Does the agent need to sleep or poll while waiting for the code?

No. wait_for_verification_code holds the request open for up to 60 seconds and returns the moment the message arrives. If nothing arrives it returns a timeout result, and the agent calls it again.

Can the agent receive SMS codes?

Yes, on a paid plan or with pay-as-you-go credits. Create the identity with channels: ["sms"] to get a dedicated, receive-only US number. Without a plan or credits the tool returns payment_required and suggests using email instead.

Humanless: disposable inboxes, dedicated US SMS numbers and TOTP for testing apps you own. Email and TOTP are free.

Get an API key