Basic 2FA Authentication
Handle 2FA using thesensitive_data parameter to securely pass secret keys:
How It Works
1
Store Secret Key
Save your TOTP secret key (from authenticator app setup) in
sensitive_data2
Reference in Task
Reference the secret by its key name (e.g.,
bu_2fa_code) in your task description3
Automatic Code Generation
Browser Use automatically generates the current 6-digit TOTP code from the secret
4
Input Code
The agent inputs the generated code into the 2FA form field
Gmail 2FA Integration
Real-world example: Logging into Gmail with 2FA:Getting Your TOTP Secret Key
When setting up 2FA on a website, you’ll see a QR code. The secret key is also provided:1
Setup 2FA
When enabling 2FA on a website, look for “Can’t scan QR code?” or “Manual entry” option
2
Copy Secret Key
Copy the alphanumeric secret key (e.g.,
JBSWY3DPEHPK3PXP)3
Store Securely
Save the secret in your password manager or environment variables
4
Use in Browser Use
Pass the secret via
sensitive_data parameterPassword Managers: Apps like 1Password display the secret key when you view a 2FA entry. You can extract it from there.
Multiple 2FA Accounts
Handle different 2FA codes for multiple accounts:SMS-based 2FA
For SMS-based 2FA, you’ll need a custom action to receive SMS codes:Email-based 2FA
Handle 2FA codes sent via email:Security Best Practices
Secure Secret Storage
Environment Variables Setup
.env
Handling 2FA Prompts
Instruct the agent clearly on when to use 2FA codes:Troubleshooting
Code Not Accepted
If the 2FA code isn’t accepted:- Check time sync: TOTP codes are time-based. Ensure your system clock is accurate
- Verify secret key: Confirm you copied the full secret key without spaces
- Wait for new code: If too much time passes, wait for the next 30-second window
Multiple Failed Attempts
Related Examples
- Form Filling - Fill login forms with credentials
- Shopping - Authenticate for shopping accounts
- Playwright Integration - Use Playwright for deterministic 2FA input