Skip to main content

Overview

Browser Use provides multiple strategies for handling authentication:
  • Cookie/Session Sync - Reuse your local browser sessions
  • Sensitive Data - Securely pass credentials to the agent
  • 2FA Integration - Automate time-based codes
  • Cloud Profiles - Persistent authentication in production

Using Your Real Browser

Connect to your existing Chrome profile to preserve all authentication:
Important: Close Chrome completely before running this. Chrome locks the profile directory.

Export/Import Storage State

Save cookies and localStorage for reuse:
1

Export Storage State

2

Import Storage State

Storage State Format:

Sensitive Data

Pass credentials securely without hardcoding:

Basic Usage

The agent automatically detects when to use sensitive data values. They’re never logged or shown in console output.

Domain-Specific Credentials

Organize credentials by domain:

2FA Authentication

Time-Based OTP (TOTP)

Automate 2FA codes with pyotp:
Browser Use automatically generates TOTP codes when it sees bu_2fa_code in sensitive data.

Custom 2FA Tool

For more control, create a custom tool:

SMS/Email 2FA

Implement human-in-the-loop for manual codes:

Production: Cloud Profiles

For production deployments, sync your local cookies to the cloud:
1

Get API Key

Create an API key at cloud.browser-use.com/new-api-key
2

Sync Local Cookies

Run the profile sync script:
This opens a browser where you log into your accounts. You’ll get a profile_id.
3

Use in Production

Your cloud browser is already logged in with your synced cookies!
Cloud profiles persist authentication across runs. No need to login every time.

Common Authentication Patterns

Form-Based Login

OAuth Flow

Multi-Step Authentication

SSO / SAML

Session Persistence

Keep Browser Alive

Maintain session across multiple agent runs:

Export State Mid-Session

Security Best Practices

1

Never Hardcode Credentials

Good:
Bad:
2

Use .gitignore

Exclude sensitive files:
.gitignore
3

Rotate Credentials

4

Monitor Authentication

Troubleshooting

Session Expired

CAPTCHA Handling

Use cloud browsers with captcha bypass:

Next Steps

Production Deployment

Deploy with @sandbox and cloud profiles

Custom Tools

Build custom authentication flows

Browser Configuration

Advanced browser settings

Sensitive Data

See more examples