browser-use-turnstile
Let a browser-use agent solve Cloudflare Turnstile. One call registers a solve_cloudflare_turnstile action on your agent's tools. When the agent lands on a page blocked by a Turnstile widget, it calls the action, which reads the sitekey from the page, gets a token from Peak, and writes the token back into the form.
A browser-use agent clicks the Turnstile checkbox, the widget decides it is not a person, and the run stalls on a form that will not submit. The model cannot fix that by reasoning harder. The token has to be minted outside the browser. This package gives the agent that move as a tool.
The action takes no arguments. The agent does not have to find the sitekey or paste a token. The action does both against the live page.
Install
pip install browser-use-turnstile
browser-use needs Python 3.11 or newer, so this package does too.
Use it
from browser_use import Agent, ChatAnthropic, Tools
from browser_use_turnstile import register_turnstile_action
tools = Tools()
register_turnstile_action(tools) # reads PEAK_API_KEY from the environment
agent = Agent(
task="Open https://example.com/login, clear any Turnstile challenge, submit the form.",
llm=ChatAnthropic(model="claude-sonnet-5-5"),
tools=tools,
)
await agent.run()
Pass the key directly with register_turnstile_action(tools, api_key="pk_...") if you do not want the environment variable. A runnable version is in examples/basic_agent.py.
What the action does
- Reads the sitekey from the current page:
[data-sitekey]first, then thechallenges.cloudflare.comiframesrcfor widgets rendered through the JS API. - Sends the sitekey and the page URL to Peak.
- Fills every
cf-turnstile-responsefield with the token, firesinputandchange, and calls the widget'sdata-callbackif the page registered one. - Tells the agent what happened in one line, so its next step is "click Submit" and not a guess.
Failures come back as an error result the model can read (no sitekey on the page, no balance, bad key) instead of an exception that ends the run.
Matching the exit IP
Turnstile scores the IP that submits the token. If your browser runs behind a proxy, pass the same one:
register_turnstile_action(tools, proxy="http://user:pass@host:port")
Without proxy, the solve goes through Peak's own IP pool. That works for most sites and fails on the ones that bind the token to the requesting IP.
Use the pieces on their own
from browser_use_turnstile import PeakClient, solve_on_page
client = PeakClient("pk_...")
token = client.solve(sitekey="0x4AAAAAAA...", url="https://example.com/login")
solve_on_page(page, url, client) is the same logic the action runs, for use inside your own custom action.
Getting a key
The action needs an API key for the solver it calls: Peak. You pay only for the solves that land, and the free trial (1,000 solves, no card) is enough to wire this up and test it. Peak also solves the Cloudflare 5-second challenge (task_type: "cloudflare5stask"); this package covers Turnstile.
$0.90 per 1,000 Turnstile solves, down to $0.35 at volume · pay only on success · 1,000 free solves · peak.fo
Troubleshooting
The failures people report with this package come down to a short list. Each one has a longer write-up on the Peak blog.
- The agent never calls the action. The model picks tools from their descriptions and from the task text. Name the challenge in the task ("clear any Turnstile challenge, then submit") the way the example above does, and keep
register_turnstile_actionbeforeAgent(...)so the tool is in the list the model sees. ERROR: no Turnstile sitekey found on this page. The action reads the DOM once; it does not wait. The agent called it before the widget rendered, or the site loads the widget from a script the selectors never see. Have the agent wait or scroll and call it again, or pass the key yourself throughsolve_on_page(page, url, client, sitekey="0x4AAA...")from a custom action. How to find a Cloudflare Turnstile sitekey covers the DevTools route and the places sites hide it (also on Hashnode).- "Token solved but the page has no cf-turnstile-response field or data-callback to receive it." The solve worked. The page renders the widget through the JS API with a callback closure and no hidden input, or it re-rendered the widget and wiped the field. cf-turnstile-response is empty lists the causes in order, and the cf-turnstile-response token explained covers what the server does with the token once it arrives.
- The page still answers 403 after the token lands. That is a different wall. A Turnstile token satisfies a widget on a form. A 403 interstitial wants a
cf_clearancecookie from the 5-second challenge, which is Peak'scloudflare5stask, not this package. Turnstile token vs cookie explains which one you need, Cloudflare Turnstile 403 walks through the fix, and the Cloudflare 5-second challenge explained covers the cookie side. - The widget shows an error code such as 110200, 300030 or 600010. Cloudflare Turnstile error codes groups them by what failed, from a domain missing on the sitekey's allowlist to a challenge run that died inside the iframe.
ERROR: No Peak API key. SetPEAK_API_KEYin the environment, or passapi_key=toregister_turnstile_action.
For the bigger picture, including why the proxy you pass to Peak should match the browser's egress IP, read How to solve Cloudflare Turnstile in 2026.
Related
Other agent wrappers for the same API: langchain-turnstile · crewai-turnstile. Browser wrappers: playwright-turnstile · patchright-turnstile · camoufox-turnstile · nodriver-turnstile · pydoll-turnstile · drissionpage-turnstile · selenium-turnstile · botasaurus-turnstile · puppeteer-extra-plugin-turnstile · crawlee-turnstile. Full list in awesome-turnstile-solvers.
If you want to know what the widget does before it hands out a token, cloudflare-turnstile-reversed documents the challenge flow, the widget parameters and the fingerprinting it runs.
Notes
Use this on sites and accounts you are allowed to automate. Respect each target's Terms of Service and robots.txt. This is tooling for legitimate agents, testing, and public-data access. Nothing here helps with credential stuffing or abuse. Not affiliated with Cloudflare or browser-use.
License
MIT
Metadata
Release files for browser-use-turnstile 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| browser_use_turnstile-0.1.1.tar.gz | 9.6 kB | Without provenance | Details for browser_use_turnstile-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| browser_use_turnstile-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for browser_use_turnstile-0.1.1-py3-none-any.whl |
Total release size: 20.2 kB
Release files / browser_use_turnstile-0.1.1.tar.gz
| Download URL | browser_use_turnstile-0.1.1.tar.gz |
|---|---|
| Size | 9.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
713ed3aad71d4b1e2d0f978fdd76e207454a4cafa606f2a51dae437cf41b2aed
|
|
BLAKE2b-256 checksum How to use checksums |
38519a13c012fa670e352fc4976c8d6c89c7f8bdaaa549a9c3077f2e9eea2a45
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.0
|
Release files / browser_use_turnstile-0.1.1-py3-none-any.whl
| Download URL | browser_use_turnstile-0.1.1-py3-none-any.whl |
|---|---|
| Size | 10.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9dba8cd2a179b21864911eabccdaa7a5aced4464692812a89c48f034d4862f6a
|
|
BLAKE2b-256 checksum How to use checksums |
ac19aa9abd77f6d3af6209900f106baede2c4160c0a0c730492f8cd500c26d7d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.0
|
Security for browser-use-turnstile 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.