networkPolicyId when you create a browser or a run. The Browser Use proxy
applies the policy to every request of that browser.
Network policies are part of API V4. The SDKs do not have methods for them
yet, so the examples use REST.
Create a policy
curl
201 with the stored policy:
Browser Use generates
id. version starts at 1 and increases by 1 with each
update.
Domain rules
Browser Use stores each domain in a normal form:- It removes leading and trailing spaces, changes letters to lower case, and removes a trailing dot.
- It converts international domain names to punycode.
- It stores
*.example.comasexample.com, because each entry also covers its subdomains. - It removes duplicate entries.
422:
- URLs, paths, and ports, such as
https://example.com/orexample.com:443. - IP addresses.
- Other wildcards, such as
shop.*.com. - A domain that is in both
allowandblock.
allow and block together. A project
has at most 100 policies. A request over a limit returns 422.
How a policy decides
An entry covers the domain and all of its subdomains. When more than one entry matches a host, the most specific entry wins. If no entry matches, the browser usesdefaultAction.
With the policy above:
To make an allowlist, set
defaultAction to "block" and put the permitted
domains in allow:
allow
does not open a domain that this blocklist blocks.
Use a policy
Standalone browsers
PutnetworkPolicyId in the body of POST /api/v4/browsers:
curl
Agent runs
PutnetworkPolicyId in the run’s browserSettings:
404.
For a follow-up run in the same session:
- If you omit
networkPolicyId, the run keeps the session’s policy. - If you send
null, the run uses no policy. - If the policy differs from the policy of the open browser, Browser Use does not reuse that browser. It starts a new browser with the new policy.
Browser Use proxy with an API key
If you use the Browser Use proxy with your API key as the proxy password, add-policy-<id> to the proxy username, for example
user-country-us-policy-6f1c2a4e-8b0d-4e7a-9f3c-2d5b7e9a1c40.
Blocked requests
The proxy refuses a blocked request with403. In the browser, the page does
not load and shows a network error. An agent sees the same error.
Change or delete a policy
PATCH /api/v4/network-policies/{id} changes only the fields that the request
contains. A domain list in the request replaces the whole list:
curl
DELETE /api/v4/network-policies/{id} returns 204. Browsers that use the
policy continue without a network policy within a few seconds. The Browser Use
security blocklist still applies.
Endpoints
See also Proxies.