Skip to content

Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.

more sensitive data docs improvements

Nick Sweeting807ca5f9656c
diff --git a/docs/customize/sensitive-data.mdx b/docs/customize/sensitive-data.mdx
index 9c8876212..97e687476 100644
--- a/docs/customize/sensitive-data.mdx
+++ b/docs/customize/sensitive-data.mdx
@@ -1,14 +1,30 @@
---
title: "Sensitive Data"
-description: "Handle sensitive information securely by preventing the model from seeing actual passwords."
+description: "Handle sensitive information securely and avoid sending PII & passwords to the LLM."
icon: "shield"
---
## Handling Sensitive Data
-When working with sensitive information like passwords, you can use the `sensitive_data` parameter to prevent the model from seeing the actual values while still allowing it to reference them in its actions.
+When working with sensitive information like passwords or PII, you can use the `Agent(sensitive_data=...)` parameter to provide sensitive strings that the model can use in actions without ever seeing directly.
-Make sure to always set [`allowed_domains`](https://docs.browser-use.com/customize/browser-settings#allowed-domains) to restrict the domains the Agent is allowed to visit when working with sensitive data or logins.
+```python
+agent = Agent(
+ task='Log into example.com as user x_username with password x_password',
+ sensitive_data={
+ 'https://example.com': {
+ 'x_username': '[email protected]',
+ 'x_password': 'abc123456', # 'x_placeholder': '<actual secret value>',
+ },
+ },
+)
+```
+
+<Note>
+
+You should also configure [`BrowserSession(allowed_domains=...)`](https://docs.browser-use.com/customize/browser-settings#allowed-domains) to prevent the Agent from visiting URLs not needed for the task.
+
+</Note>
### Basic Usage
@@ -71,15 +87,20 @@ This approach ensures that sensitive information remains secure while still allo
### Best Practices
- Always restrict your sensitive data to only the exact domains that need it, `https://travel.example.com` is better than `*.example.com`
-- Always restrict `BrowserSession(allowed_domains=[...])` to only the domains the agent needs to visit to accomplish its task. This helps guard against prompt injection attacks, jailbreaks, and LLM mistakes.
-- Don't use `sensitive_data` for login credentials, it's better to log into the sites the agent needs in advance and reuse the cookies when the Agent runs:
- ```bash
- $ playwright open https://accounts.google.com --save-storage google_cookies.json
- ```
- Then use those cookies when the agent runs:
- ```python
- agent = Agent(..., browser_session=BrowserSession(storage_state='./google_cookies.json'))
- ```
+- Always restrict [`BrowserSession(allowed_domains=[...])`](https://docs.browser-use.com/customize/browser-settings#allowed-domains) to only the domains the agent needs to visit to accomplish its task. This helps guard against prompt injection attacks, jailbreaks, and LLM mistakes.
+- Only use `sensitive_data` for strings that can be inputted verbatim as text. The LLM never sees the actual values, so it can't "understand" them, adapt them, or split them up for multiple input fields. For example, you can't ask the Agent to click through a datepicker UI to input the sensitive value `1990-12-31`. For these situations you can implement a [custom function](/customize/custom-functions) the LLM can call that mutates the DOM in python.
+- Don't use `sensitive_data` for login credentials, it's better to use [`storage_state`](docs.browser-use.com/customize/browser-settings#storage-state) or a [`user_data_dir`](/customize/browser-settings#user-data-dir) to log into the sites the agent needs in advance & reuse the cookies:
+
+```bash
+# open a browser to log into the sites you need your agent to be able to access
+$ playwright open https://accounts.google.com --save-storage google_cookies.json
+```
+
+Then use those cookies when the agent runs:
+
+```python
+agent = Agent(..., browser_session=BrowserSession(storage_state='./google_cookies.json'))
+```
<Warning>
@@ -90,6 +111,41 @@ It's recommended to set `Agent(use_vision=False)` when working with `sensitive_d
</Warning>
+<!-- old section titles to avoid breaking anchor links: -->
+<a name="allowed_domains"></a>
+<a name="domain-pattern-format"></a>
+
+
+### Allowed Domains
+
+Domain patterns in `sensitive_data` follow the same format as [`allowed_domains`](https://docs.browser-use.com/customize/browser-settings#allowed-domains):
+
+- `example.com` - Matches only `https://example.com/*`
+- `*.example.com` - Matches `https://example.com/*` and any subdomain `https://*.example.com/*`
+- `http*://example.com` - Matches both `http://` and `https://` protocols for `example.com/*`
+- `chrome-extension://*` - Matches any Chrome extension URL e.g. `chrome-extension://anyextensionid/options.html`
+
+> **Security Warning**: For security reasons, certain patterns are explicitly rejected:
+>
+> - Wildcards in TLD part (e.g., `example.*`) are **not allowed** (`google.*` would match `google.ninja`, `google.pizza`, etc. which is a bad idea)
+> - Embedded wildcards (e.g., `g*e.com`) are rejected to prevent overly broad matches
+> - Multiple wildcards like `*.*.domain` are not supported currently, open an issue if you need this feature
+
+The default protocol when no scheme is specified is now `https://` for enhanced security.
+
+For convenience the system will validate that all domain patterns used in `Agent(sensitive_data)` are also included in `BrowserSession(allowed_domains)`.
+
+### Missing or Empty Values
+
+When working with sensitive data, keep these details in mind:
+
+- If a key referenced by the model (`<secret>key_name</secret>`) is missing from your `sensitive_data` dictionary, a warning will be logged but the substitution tag will be preserved.
+- If you provide an empty value for a key in the `sensitive_data` dictionary, it will be treated the same as a missing key.
+- The system will always attempt to process all valid substitutions, even if some keys are missing or empty.
+
+
+---
+
### Full Example
Here's a more complex example demonstrating multiple domains and sensitive data values.
@@ -141,35 +197,3 @@ With this approach:
1. The Google credentials (`x_email` and `x_pass`) will only be used on Google domains (any subdomain, https only)
2. The API key (`x_api_key`) will only be used whtin the specific Chrome extension with id `abcd1243`
3. The auth code (`x_authcode`) will only be used on `http://example.com/*` or `https://example.com/*`
-
-
-<!-- old section titles to avoid breaking anchor links: -->
-<a name="allowed_domains"></a>
-<a name="domain-pattern-format"></a>
-
-
-### Allowed Domains
-
-Domain patterns in `sensitive_data` follow the same format as [`allowed_domains`](https://docs.browser-use.com/customize/browser-settings#allowed-domains):
-
-- `example.com` - Matches only `https://example.com/*`
-- `*.example.com` - Matches `https://example.com/*` and any subdomain `https://*.example.com/*`
-- `http*://example.com` - Matches both `http://` and `https://` protocols for `example.com/*`
-- `chrome-extension://*` - Matches any Chrome extension URL e.g. `chrome-extension://anyextensionid/options.html`
-
-> **Security Warning**: For security reasons, certain patterns are explicitly rejected:
-> - Wildcards in TLD part (e.g., `example.*`) are **not allowed** (`google.*` would match `google.ninja`, `google.pizza`, etc. which is a bad idea)
-> - Embedded wildcards (e.g., `g*e.com`) are rejected to prevent overly broad matches
-> - Multiple wildcards like `*.*.domain` are not supported currently, open an issue if you need this feature
-
-The default protocol when no scheme is specified is now `https://` for enhanced security.
-
-For convenience the system will validate that all domain patterns used in `Agent(sensitive_data)` are also included in `BrowserSession(allowed_domains)`.
-
-### Missing or Empty Values
-
-When working with sensitive data, keep these details in mind:
-
-- If a key referenced by the model (`<secret>key_name</secret>`) is missing from your `sensitive_data` dictionary, a warning will be logged but the substitution tag will be preserved.
-- If you provide an empty value for a key in the `sensitive_data` dictionary, it will be treated the same as a missing key.
-- The system will always attempt to process all valid substitutions, even if some keys are missing or empty.