Skip to main content

crewai-turnstile

Give a CrewAI agent the ability to solve Cloudflare Turnstile. A BaseTool that takes a page URL and a sitekey, calls Peak, and hands back a token. A crew that browses the web and hits a Turnstile challenge gets a move to make instead of getting stuck.

Python 3.10+ crewai tool MIT License


A crew that browses the web runs into Cloudflare Turnstile sooner or later. The widget wants a token that Cloudflare mints after its own checks pass, and a retry loop or a fresh proxy won't produce one. This package gives the crew a BaseTool for that step: pass a URL and a sitekey, get a token back.

The tool never touches a browser. It sends one request to the Peak API and returns the answer, so it works in any crew, whether the agents drive Playwright, Selenium or a raw HTTP client. Pair it with whatever tool your agent already uses to read the DOM (to get the sitekey) and to run JS (to put the token back); see Closing the loop below.

Install

pip install crewai-turnstile

Use it

from crewai_turnstile import PeakTurnstileTool

tool = PeakTurnstileTool(api_key="pk_...")  # or set PEAK_API_KEY
token = tool.run(url="https://example.com/login", sitekey="0x4AAAAAAA...")

Hand it to an agent like any other tool:

from crewai import Agent
from crewai_turnstile import PeakTurnstileTool

agent = Agent(
    role="Web researcher",
    goal="Fetch pages and clear any Turnstile challenge blocking them",
    backstory="You browse pages via tools and solve Turnstile when it blocks one.",
    tools=[*your_browser_tools, PeakTurnstileTool(api_key=api_key)],
)

The agent decides when to call it, most often after a browsing tool reports it's stuck on a Cloudflare challenge. The tool's description is written for that: an LLM reading the tool list will reach for solve_cloudflare_turnstile when it sees a Turnstile widget blocking a page.

Closing the loop

Reading the sitekey and injecting the token both happen on a live page, which is specific to whatever browser your crew drives, so this package doesn't pick one for you. inject.py ships the JS every other Peak wrapper package uses, so you can call it from whichever execute_script / page.evaluate your stack exposes:

from crewai_turnstile import build_injection_script

page.evaluate(build_injection_script(token))          # Playwright
driver.execute_script(build_injection_script(token))  # Selenium

It fills every cf-turnstile-response field and fires the widget's data-callback if the page registered one, the same two places a real form submit reads from.

Matching the exit IP

Turnstile scores the IP that submits the token. If your agent's browser runs behind a proxy, pass the same one so the token and the request line up:

tool.run(url=url, sitekey=sitekey, proxy="http://user:pass@host:port")

Leave proxy out and the tool solves through Peak's own IP pool instead. Fine for most sites, wrong for the ones that bind the token to the requesting IP.

Errors come back as text, not exceptions

An agent copes better with a failure it can read than with a crash that kills the run. PeakTurnstileTool returns "ERROR: <reason>" (bad sitekey, no balance, no key configured) instead of raising, so the agent's next step can be "try a different sitekey" rather than "the whole crew run died." Call PeakClient.solve() directly from crewai_turnstile.peak if you want exceptions instead.

Getting a key

The tool 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.

Peak
$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 tool returns failures as a string that starts with ERROR:. Print the tool output, or read the crew's verbose log, to see which one you have.

  • ERROR: No Peak API key. Neither api_key= nor PEAK_API_KEY held a key. Keys start with pk_; the free one comes from the dashboard.
  • ERROR: Peak request failed: ... The request never reached Peak. Check DNS, the firewall, and any HTTPS_PROXY variable in the environment, since urllib honours it.
  • ERROR: followed by Peak's own reason, or Peak solve failed. Peak answered with success: false. Common causes: an empty balance, a sitekey that does not belong to the URL, or a proxy Peak could not connect through. Peak does not bill a failed solve. The Cloudflare Turnstile error codes post covers the widget-side codes (110200, 300030, 600010 and the rest).
  • The agent passes a sitekey that isn't on the page. An LLM will invent a plausible 0x4AAAAAAA... string if no tool gave it the real one. Have a browsing tool return the widget's data-sitekey attribute and tell the agent in its task to copy that value. How to find a Cloudflare Turnstile sitekey shows where sites hide it.
  • A second call returns the same token. Versions before 0.1.2 left CrewAI's tool cache on, and CrewAI replays the stored result for a repeated (url, sitekey) pair. A Turnstile token works once, so the replayed one is dead. Upgrade to 0.1.2, which turns the cache off for this tool. Pass your own cache_function= if you want it back.
  • build_injection_script ran and the submit button stays disabled. The script fills every cf-turnstile-response field and calls the function named in the widget's data-callback attribute. A site that passes a closure to turnstile.render({callback: ...}) keeps that function out of reach. Submit the form from your browsing tool, or call the site's own handler with the token. cf-turnstile-response is empty and the cf-turnstile-response token explained cover the field.
  • The submit returns 403 or the form page again. The site refused the token. A token is single-use and expires 300 seconds after Cloudflare issues it, so an agent that plans three more steps before it submits can run out the clock. Pass proxy with the browser's own egress so Peak mints the token from the address that submits it. Cloudflare Turnstile 403 covers the refusal.
  • The page shows "Just a moment..." and has no widget. That page is the managed 5-second challenge, a separate check from the Turnstile widget. It wants a cf_clearance cookie, and this tool returns widget tokens. Turnstile token vs cookie explains the difference, and the Cloudflare 5-second challenge explained covers the interstitial.

A longer read: the 2026 Turnstile developer guide.

Other agent wrappers for the same API: langchain-turnstile · browser-use-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. No browser: cloudscraper-turnstile · turnstile-curl · scrapy-turnstile · scrapling-turnstile. Full list in awesome-turnstile-solvers.

cloudflare-turnstile-reversed documents the challenge flow, the widget parameters and the fingerprinting the widget runs before it hands out a token.

Notes

Use this on sites and accounts you're 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 CrewAI Inc.

License

MIT

Metadata

Release files for crewai-turnstile 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for crewai-turnstile 0.1.2
File Size Uploaded Provenance Actions
crewai_turnstile-0.1.2.tar.gz 11.7 kB Without provenance Details for crewai_turnstile-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for crewai-turnstile 0.1.2
File Interpreter ABI Platform Actions
crewai_turnstile-0.1.2-py3-none-any.whl Python 3 none any Details for crewai_turnstile-0.1.2-py3-none-any.whl

Total release size: 23.3 kB

Release files / crewai_turnstile-0.1.2.tar.gz

Download URL crewai_turnstile-0.1.2.tar.gz
Size 11.7 kB
Tags Source
SHA-256 checksum
How to use checksums
955dfc1e805a88946a82f192903e694eec9fa3e712584f9b262db1400b5754e5
BLAKE2b-256 checksum
How to use checksums
f80b9242669fd6d01d39aeb0b6ed1cc2f4138f858fda9a6225c7b21efb76165f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.0

Release files / crewai_turnstile-0.1.2-py3-none-any.whl

Download URL crewai_turnstile-0.1.2-py3-none-any.whl
Size 11.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
55cc42aac9f3fcf5c27da4d38bfa5306325bca58bece94c12a1eae0758896184
BLAKE2b-256 checksum
How to use checksums
c75d8f478c443ee240134861f08098f6858c712d9013d3c4cf81f2a851876a02
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.0

Security for crewai-turnstile 0.1.2

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page