[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"blog-post-en-proxy-setup-for-ai-agents":3},{"success":4,"payload":5,"related":83,"errors":180},true,{"id":6,"slug":7,"title":8,"excerpt":9,"body_html":10,"meta_title":11,"meta_description":12,"canonical_url":13,"canonical_override":14,"og_title":15,"og_description":16,"og_image_url":17,"faq_json":18,"key_takeaways":34,"allow_index":4,"noindex_google_only":40,"allow_follow":4,"published_at":41,"updated_at":42,"content_updated_at":43,"featured_image_url":44,"featured_image_alt":8,"card_image_url":45,"reading_time_minutes":46,"author":47,"categories":51,"tags":58,"alternates":75,"locale_paths":81,"views":82},210,"proxy-setup-for-ai-agents","Proxy Setup for AI Agents: browser-use, Crawl4AI and an MCP Server","Agents on cloud VMs exit from datacenter IPs. Here is current, working proxy configuration for browser-use, Crawl4AI and an MCP server, with a sticky-vs-rotating decision table and the cost traps to avoid.","\u003Cp>An AI agent on a cloud VM leaves from a datacenter IP. Sites see that IP before they see anything else, so the agent gets results for the wrong country, hits rate limits it never caused, or lands in a CAPTCHA loop it can't get out of. A good proxy setup for AI agents fixes the egress problem in the browser config, never in the prompt. Multi-step tasks keep one sticky IP from start to finish, and parallel fetches rotate. Below is working configuration for browser-use, Crawl4AI and an MCP server, plus the cost controls and the failure modes that come up most often.\u003C\u002Fp>\n\n\u003Ch2>Why a proxy setup for AI agents matters more than for scripts\u003C\u002Fh2>\n\u003Cp>Agents need a proxy for the same three reasons scrapers do: geography, rate limits and IP reputation. They need it more urgently because they run unattended and make their own retry decisions. A script that gets blocked stops. An agent that gets blocked tries again, rephrases, opens a new tab and tries again, and every attempt costs bandwidth and LLM tokens.\u003C\u002Fp>\n\u003Cul>\n\u003Cli>Geography. Prices, search results, stock and legal notices change by country. An agent comparing prices for a German customer from a US-East VM is collecting the wrong data. Country targeting in the proxy username fixes that without touching the agent's logic. \u003Ca href=\"\u002Fblog\u002Fhow-geo-targeted-proxies-work\">How geo-targeted proxies work\u003C\u002Fa> explains the mechanics.\u003C\u002Fli>\n\u003Cli>Cloud egress reputation. AWS, GCP, Azure and Hetzner ranges are public, and IP-reputation services score them as hosting, not consumer access. Many sites challenge or throttle these ranges on sight, whatever the request looks like. Our \u003Ca href=\"\u002Fblog\u002Fip-reputation-fraud-scoring-guide\">IP reputation deep-dive\u003C\u002Fa> covers how that scoring works.\u003C\u002Fli>\n\u003Cli>Shared rate limits. Several agents behind one NAT gateway share a single public IP. Each one is polite on its own, but together they look like one aggressive client.\u003C\u002Fli>\n\u003C\u002Ful>\n\u003Cp>What a proxy does \u003Cem>not\u003C\u002Fem> fix: a residential IP doesn't make an automated browser look human. Behavioural and fingerprint detection still works, and our companion piece on \u003Ca href=\"\u002Fblog\u002Fhow-websites-detect-ai-browser-agents\">how websites detect AI browser agents\u003C\u002Fa> shows how. Use proxies to get correct, geo-accurate data and to spread load fairly. Don't use them to get around a site that has told automation to stay out.\u003C\u002Fp>\n\n\u003Ch2>Sticky sessions vs rotation: decide per task, not per project\u003C\u002Fh2>\n\u003Cp>Rule of thumb: \u003Cstrong>if the task carries state, pin the IP; if it doesn't, rotate.\u003C\u002Fstrong> A login → navigate → add-to-cart → checkout flow has to keep one exit IP from start to finish, because many sites bind session cookies, CSRF tokens or risk scores to the IP that opened the session. If the IP changes mid-flow, you'll often get logged out or re-challenged. Independent page fetches are the reverse: spreading them across IPs keeps each one under per-IP limits.\u003C\u002Fp>\n\u003Cp>With a backconnect gateway you switch modes by changing the username. \u003Ccode>USERNAME-sid-abc123-ttl-10m\u003C\u002Fcode> keeps the same exit IP for as long as you reuse that session ID. A plain \u003Ccode>USERNAME\u003C\u002Fcode> rotates. \u003Ccode>USERNAME-country-US\u003C\u002Fcode> pins the country. The \u003Ca href=\"\u002Fblog\u002Fsticky-vs-rotating-proxy-sessions\">sticky vs rotating sessions guide\u003C\u002Fa> covers session lifetimes in more depth.\u003C\u002Fp>\n\u003Ctable>\n\u003Cthead>\u003Ctr>\u003Cth>Agent task\u003C\u002Fth>\u003Cth>IP mode\u003C\u002Fth>\u003Cth>Why\u003C\u002Fth>\u003C\u002Ftr>\u003C\u002Fthead>\n\u003Ctbody>\n\u003Ctr>\u003Ctd>Log in, then act inside an account\u003C\u002Ftd>\u003Ctd>Sticky, one session ID per account\u003C\u002Ftd>\u003Ctd>Session cookies and risk scores are often tied to the IP that logged in. A mid-session IP change looks like account takeover.\u003C\u002Ftd>\u003C\u002Ftr>\n\u003Ctr>\u003Ctd>Multi-page form or checkout test\u003C\u002Ftd>\u003Ctd>Sticky for the whole flow\u003C\u002Ftd>\u003Ctd>CSRF tokens and cart state survive. A failed step can be retried from the same IP.\u003C\u002Ftd>\u003C\u002Ftr>\n\u003Ctr>\u003Ctd>Research agent reading 50 unrelated pages\u003C\u002Ftd>\u003Ctd>Rotating\u003C\u002Ftd>\u003Ctd>No shared state. Spreading requests avoids per-IP throttling on any one domain.\u003C\u002Ftd>\u003C\u002Ftr>\n\u003Ctr>\u003Ctd>Bulk crawl for RAG ingestion\u003C\u002Ftd>\u003Ctd>Rotating, or a small pool of sticky slots\u003C\u002Ftd>\u003Ctd>Rotation spreads load. Sticky slots let a JS-heavy site keep its cookies across a few pages.\u003C\u002Ftd>\u003C\u002Ftr>\n\u003Ctr>\u003Ctd>Geo comparison (same URL, several countries)\u003C\u002Ftd>\u003Ctd>Country-targeted, rotating within a country\u003C\u002Ftd>\u003Ctd>You want one answer per market, not one per IP.\u003C\u002Ftd>\u003C\u002Ftr>\n\u003Ctr>\u003Ctd>Monitoring one page every N minutes\u003C\u002Ftd>\u003Ctd>Rotating\u003C\u002Ftd>\u003Ctd>Repeated hits from one IP build a pattern. Rotation keeps the load per IP low.\u003C\u002Ftd>\u003C\u002Ftr>\n\u003C\u002Ftbody>\n\u003C\u002Ftable>\n\n\u003Ch2>browser-use: proxy configuration in the current API\u003C\u002Fh2>\n\u003Cp>browser-use takes a \u003Ccode>proxy=ProxySettings(...)\u003C\u002Fcode> argument on \u003Ccode>Browser\u003C\u002Fcode> (an alias of \u003Ccode>BrowserSession\u003C\u002Fcode>), with \u003Ccode>server\u003C\u002Fcode>, \u003Ccode>username\u003C\u002Fcode>, \u003Ccode>password\u003C\u002Fcode> and \u003Ccode>bypass\u003C\u002Fcode> fields. The credentials go to the browser and never into the LLM context. Under the hood, browser-use launches Chromium with \u003Ccode>--proxy-server\u003C\u002Fcode> and answers the proxy's auth challenge over CDP (\u003Ccode>Fetch.authRequired\u003C\u002Fcode>), so you never need to put credentials in the URL. Note the import path: \u003Ccode>ProxySettings\u003C\u002Fcode> lives in \u003Ccode>browser_use.browser\u003C\u002Fcode>, not the package root (see the \u003Ca href=\"https:\u002F\u002Fdocs.browser-use.com\u002Fopen-source\u002Fcustomize\u002Fbrowser\u002Fall-parameters\" rel=\"noopener noreferrer\">browser parameters reference\u003C\u002Fa> and \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fbrowser-use\u002Fbrowser-use\u002Fblob\u002Fmain\u002Fbrowser_use\u002Fbrowser\u002Fprofile.py\" rel=\"noopener noreferrer\">\u003Ccode>profile.py\u003C\u002Fcode>\u003C\u002Fa>).\u003C\u002Fp>\n\u003Cpre>\u003Ccode class=\"language-python\">import asyncio\nimport os\nimport uuid\n\nfrom browser_use import Agent, Browser, ChatOpenAI\nfrom browser_use.browser import ProxySettings\n\nPROXY_USER = os.environ[\"PROXYHAT_USER\"]\nPROXY_PASS = os.environ[\"PROXYHAT_PASS\"]\n\n\nasync def run_checkout_test() -&gt; None:\n    # One sticky session ID for the whole flow, so login -&gt; cart -&gt; checkout keeps one exit IP.\n    session_id = uuid.uuid4().hex[:12]\n\n    browser = Browser(\n        headless=True,\n        proxy=ProxySettings(\n            server=\"http:\u002F\u002Fgate.proxyhat.com:8080\",\n            username=f\"{PROXY_USER}-sid-{session_id}-ttl-10m\",\n            password=PROXY_PASS,\n            bypass=\"localhost,127.0.0.1\",\n        ),\n        # Keep the agent on the site under test; it also limits where sensitive_data can be typed.\n        allowed_domains=[\"https:\u002F\u002Fstaging.example-shop.com\"],\n        # Chromium switch: don't download images at all.\n        args=[\"--blink-settings=imagesEnabled=false\"],\n    )\n\n    agent = Agent(\n        task=\"Log in with x_user \u002F x_pass, add the cheapest USB-C cable to the cart, \"\n             \"stop at the payment page and report the order total.\",\n        llm=ChatOpenAI(model=os.environ[\"OPENAI_MODEL\"]),\n        browser=browser,\n        # The model sees the placeholders x_user \u002F x_pass, never the values.\n        sensitive_data={\n            \"https:\u002F\u002Fstaging.example-shop.com\": {\n                \"x_user\": os.environ[\"SHOP_USER\"],\n                \"x_pass\": os.environ[\"SHOP_PASS\"],\n            }\n        },\n        use_vision=False,   # no screenshots in every step: fewer tokens\n        max_failures=2,     # default is 5; each failure is another round of page loads\n    )\n    history = await agent.run(max_steps=25)   # default is 500\n    print(history.final_result())\n\n\nasyncio.run(run_checkout_test())\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>Notes on this pattern:\u003C\u002Fp>\n\u003Cul>\n\u003Cli>Use the HTTP port with authenticated proxies. Chromium's \u003Ca href=\"https:\u002F\u002Fchromium.googlesource.com\u002Fchromium\u002Fsrc\u002F+\u002FHEAD\u002Fnet\u002Fdocs\u002Fproxy.md\" rel=\"noopener noreferrer\">network stack docs\u003C\u002Fa> state that no authentication methods are supported for SOCKSv5, so \u003Ccode>socks5:\u002F\u002F…:1080\u003C\u002Fcode> with credentials will fail in any Chromium-based agent. Use \u003Ccode>http:\u002F\u002Fgate.proxyhat.com:8080\u003C\u002Fcode>.\u003C\u002Fli>\n\u003Cli>Proxy credentials are not \u003Ccode>sensitive_data\u003C\u002Fcode>. \u003Ccode>sensitive_data\u003C\u002Fcode> is for values the agent has to type into pages. Proxy credentials go in \u003Ccode>ProxySettings\u003C\u002Fcode>, which the model never sees. Don't paste a proxy URL into the \u003Ccode>task\u003C\u002Fcode> string \"so the agent knows\".\u003C\u002Fli>\n\u003Cli>\u003Ccode>allowed_domains\u003C\u002Fcode> matters more than it looks. browser-use logs a warning if you pass \u003Ccode>sensitive_data\u003C\u002Fcode> without locking domains down, because a prompt-injected page could otherwise talk the agent into typing secrets somewhere else.\u003C\u002Fli>\n\u003Cli>Cloud mode is a different egress. \u003Ccode>Browser(use_cloud=True)\u003C\u002Fcode> runs the browser on Browser Use Cloud with its own proxies. Your \u003Ccode>ProxySettings\u003C\u002Fcode> apply to the local or \u003Ccode>cdp_url\u003C\u002Fcode> browser you launch yourself.\u003C\u002Fli>\n\u003Cli>Default extensions save bandwidth. \u003Ccode>enable_default_extensions\u003C\u002Fcode> is on by default and loads uBlock Origin Lite plus a cookie-banner handler, so most ads and trackers never count against your traffic.\u003C\u002Fli>\n\u003C\u002Ful>\n\n\u003Ch2>Crawl4AI: per-crawl proxies, rotation and sticky sessions\u003C\u002Fh2>\n\u003Cp>In Crawl4AI, set the proxy per crawl on \u003Ccode>CrawlerRunConfig\u003C\u002Fcode>, either as \u003Ccode>proxy_config\u003C\u002Fcode> or through a \u003Ccode>proxy_rotation_strategy\u003C\u002Fcode>. The \u003Ca href=\"https:\u002F\u002Fdocs.crawl4ai.com\u002Fadvanced\u002Fproxy-security\u002F\" rel=\"noopener noreferrer\">proxy docs\u003C\u002Fa> mark the old \u003Ccode>BrowserConfig\u003C\u002Fcode> \u003Ccode>proxy\u003C\u002Fcode> argument as deprecated and recommend configuring proxies per request. For sticky behaviour, \u003Ccode>proxy_session_id\u003C\u002Fcode> pins one proxy from the strategy to every crawl that shares that ID.\u003C\u002Fp>\n\u003Cp>A backconnect gateway is a single host, so \"a list of proxies\" means a list of \u003Cem>session usernames\u003C\u002Fem>. Each session ID is a slot with its own exit IP, and round-robin spreads URLs across the slots:\u003C\u002Fp>\n\u003Cpre>\u003Ccode class=\"language-python\">import asyncio\nimport os\nimport uuid\n\nfrom crawl4ai import (AsyncWebCrawler, BrowserConfig, CacheMode,\n                      CrawlerRunConfig, ProxyConfig, RoundRobinProxyStrategy)\n\nUSER = os.environ[\"PROXYHAT_USER\"]\nPASS = os.environ[\"PROXYHAT_PASS\"]\n\n\ndef slot() -&gt; ProxyConfig:\n    # One sticky session per slot, so each slot keeps one exit IP.\n    sid = uuid.uuid4().hex[:10]\n    return ProxyConfig(\n        server=\"http:\u002F\u002Fgate.proxyhat.com:8080\",\n        username=f\"{USER}-sid-{sid}-ttl-10m\",\n        password=PASS,\n    )\n\n\nstrategy = RoundRobinProxyStrategy([slot() for _ in range(8)])\n\nbrowser_cfg = BrowserConfig(\n    headless=True,\n    text_mode=True,   # tries to disable images and other heavy content\n    avoid_ads=True,   # blocks common ad\u002Ftracker domains\n)\n\nbulk_cfg = CrawlerRunConfig(\n    proxy_rotation_strategy=strategy,   # next slot for each URL\n    cache_mode=CacheMode.BYPASS,\n    check_robots_txt=True,\n    max_retries=1,\n)\n\n\nasync def main(urls: list[str]) -&gt; None:\n    async with AsyncWebCrawler(config=browser_cfg) as crawler:\n        results = await crawler.arun_many(urls, config=bulk_cfg)\n        for r in results:\n            print(r.url, r.success, len(r.markdown or \"\"))\n\n        # Stateful sequence: same proxy slot AND same browser page for every step.\n        step_cfg = bulk_cfg.clone(proxy_session_id=\"acct-42\", session_id=\"acct-42\")\n        await crawler.arun(\"https:\u002F\u002Fexample.com\u002Flogin\", config=step_cfg)\n        await crawler.arun(\"https:\u002F\u002Fexample.com\u002Faccount\u002Forders\", config=step_cfg)\n\n\nasyncio.run(main([\"https:\u002F\u002Fexample.com\u002Fa\", \"https:\u002F\u002Fexample.com\u002Fb\"]))\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>Two settings are easy to mix up. \u003Ccode>session_id\u003C\u002Fcode> keeps the same \u003Cem>browser page\u003C\u002Fem> across \u003Ccode>arun()\u003C\u002Fcode> calls, and \u003Ccode>proxy_session_id\u003C\u002Fcode> keeps the same \u003Cem>proxy\u003C\u002Fem>. A stateful flow needs both. For geo-pinned rotation instead of sticky slots, use a single \u003Ccode>ProxyConfig\u003C\u002Fcode> with the username \u003Ccode>USERNAME-country-US\u003C\u002Fcode>.\u003C\u002Fp>\n\u003Cp>A retry-amplification trap: \u003Ccode>proxy_config\u003C\u002Fcode> also accepts a \u003Cem>list\u003C\u002Fem> of proxies to fall back through, and the retry loop in \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Funclecode\u002Fcrawl4ai\u002Fblob\u002Fmain\u002Fcrawl4ai\u002Fasync_webcrawler.py\" rel=\"noopener noreferrer\">\u003Ccode>async_webcrawler.py\u003C\u002Fcode>\u003C\u002Fa> walks the whole list on each attempt. A blocked URL can therefore be fetched up to \u003Ccode>(max_retries + 1) × len(list)\u003C\u002Fcode> times. With 10 fallbacks and \u003Ccode>max_retries=3\u003C\u002Fcode>, that's 40 full page loads for one URL that was never going to load. Keep the list short and set \u003Ccode>max_retries\u003C\u002Fcode> on purpose.\u003C\u002Fp>\n\n\u003Ch2>Giving an MCP assistant proxied web access\u003C\u002Fh2>\n\u003Cp>You have two options: run Microsoft's Playwright MCP server with a proxy in its config, or write a small MCP tool that fetches through the proxy and returns text. Use the first when the assistant has to click and type. Use the second when it only needs to read pages, because that's far cheaper per call.\u003C\u002Fp>\n\n\u003Ch3>Option 1: Playwright MCP with an authenticated proxy\u003C\u002Fh3>\n\u003Cp>\u003Ccode>@playwright\u002Fmcp\u003C\u002Fcode> has \u003Ccode>--proxy-server\u003C\u002Fcode> and \u003Ccode>--proxy-bypass\u003C\u002Fcode> flags (\u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fmicrosoft\u002Fplaywright-mcp\" rel=\"noopener noreferrer\">README\u003C\u002Fa>). For a proxy that needs credentials, use the JSON config file instead. Its \u003Ccode>browser.launchOptions\u003C\u002Fcode> is passed straight to Playwright, whose \u003Ca href=\"https:\u002F\u002Fplaywright.dev\u002Fdocs\u002Fnetwork#http-proxy\" rel=\"noopener noreferrer\">proxy option\u003C\u002Fa> takes separate \u003Ccode>username\u003C\u002Fcode> and \u003Ccode>password\u003C\u002Fcode> fields:\u003C\u002Fp>\n\u003Cpre>\u003Ccode class=\"language-json\">{\n  \"browser\": {\n    \"browserName\": \"chromium\",\n    \"isolated\": true,\n    \"launchOptions\": {\n      \"headless\": true,\n      \"proxy\": {\n        \"server\": \"http:\u002F\u002Fgate.proxyhat.com:8080\",\n        \"username\": \"USERNAME-sid-mcp01-ttl-10m\",\n        \"password\": \"PASSWORD\"\n      }\n    }\n  },\n  \"capabilities\": [\"core\"]\n}\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cpre>\u003Ccode class=\"language-bash\">npx @playwright\u002Fmcp@latest --config .\u002Fplaywright-mcp.json --image-responses omit\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>Keep this file out of the repository and readable only by the user running the server. The session ID here means the whole assistant session shares one IP, which fits \"log in and do X\". Restart with a new ID when you want a fresh IP. \u003Ccode>--image-responses omit\u003C\u002Fcode> stops screenshots from going back to the model. \u003Ccode>\"isolated\": true\u003C\u002Fcode> (the \u003Ccode>--isolated\u003C\u002Fcode> flag) keeps the profile in memory, so cookies don't leak between tasks. The README also points out that \u003Ccode>--allowed-origins\u003C\u002Fcode> and \u003Ccode>--blocked-origins\u003C\u002Fcode> are \u003Cem>not\u003C\u002Fem> a security boundary. Treat them as hygiene, not protection.\u003C\u002Fp>\n\n\u003Ch3>Option 2: a minimal proxied fetch tool with the official MCP Python SDK\u003C\u002Fh3>\n\u003Cp>The Python SDK's v2 renamed \u003Ccode>FastMCP\u003C\u002Fcode> to \u003Ccode>MCPServer\u003C\u002Fcode> (\u003Ca href=\"https:\u002F\u002Fpy.sdk.modelcontextprotocol.io\u002Fmigration\u002F\" rel=\"noopener noreferrer\">migration guide\u003C\u002Fa>). Code written for v1 with \u003Ccode>from mcp.server.fastmcp import FastMCP\u003C\u002Fcode> needs the new import. Here is a read-only tool that fetches through the gateway, caps the response size and never puts the proxy URL in its output:\u003C\u002Fp>\n\u003Cpre>\u003Ccode class=\"language-python\">import os\nimport re\n\nimport httpx\nfrom mcp.server import MCPServer\n\nmcp = MCPServer(\"proxied-fetch\")\n\n_USER = os.environ[\"PROXYHAT_USER\"]\n_PASS = os.environ[\"PROXYHAT_PASS\"]\n_MAX_BYTES = 1_500_000\n_COUNTRY = re.compile(r\"^[A-Za-z]{2}$\")\n_SESSION = re.compile(r\"^[A-Za-z0-9]{1,24}$\")\n\n\ndef _proxy(country: str | None, session: str | None) -&gt; str:\n    user = _USER\n    # Validate model-supplied values: they end up inside the proxy username.\n    if session:\n        if not _SESSION.match(session):\n            raise ValueError(\"session must be 1-24 alphanumerics\")\n        user = f\"{_USER}-sid-{session}-ttl-10m\"\n    elif country:\n        if not _COUNTRY.match(country):\n            raise ValueError(\"country must be a 2-letter code\")\n        user = f\"{_USER}-country-{country.upper()}\"\n    return f\"http:\u002F\u002F{user}:{_PASS}@gate.proxyhat.com:8080\"\n\n\n@mcp.tool()\nasync def fetch_page(url: str, country: str | None = None, session: str | None = None) -&gt; str:\n    \"\"\"Fetch a public http(s) page through a residential proxy and return its text.\n\n    country: optional 2-letter exit country. session: optional ID to reuse one exit IP.\n    \"\"\"\n    if not url.startswith((\"http:\u002F\u002F\", \"https:\u002F\u002F\")):\n        return \"error: only http(s) URLs are allowed\"\n    try:\n        async with httpx.AsyncClient(proxy=_proxy(country, session), timeout=30,\n                                     follow_redirects=True) as client:\n            async with client.stream(\"GET\", url) as resp:\n                body = b\"\"\n                async for chunk in resp.aiter_bytes():\n                    body += chunk\n                    if len(body) &gt; _MAX_BYTES:\n                        break\n        text = body.decode(resp.encoding or \"utf-8\", errors=\"replace\")\n        return f\"HTTP {resp.status_code} {resp.url}\\n\\n{text[:200_000]}\"\n    except ValueError as e:\n        return f\"error: {e}\"\n    except httpx.HTTPError as e:\n        # Only the exception type: some messages can echo the proxy URL.\n        return f\"error: fetch failed ({type(e).__name__})\"\n\n\nif __name__ == \"__main__\":\n    mcp.run(transport=\"stdio\")\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>Register it with your MCP client as a stdio server. Pass \u003Ccode>PROXYHAT_USER\u003C\u002Fcode> and \u003Ccode>PROXYHAT_PASS\u003C\u002Fcode> through the client's \u003Ccode>env\u003C\u002Fcode> block, never through tool arguments. In Claude Code, for example, that is \u003Ccode>claude mcp add --env PROXYHAT_USER=… --env PROXYHAT_PASS=… --transport stdio proxied-fetch -- python server.py\u003C\u002Fcode>. Keep \u003Ccode>--transport\u003C\u002Fcode> between the last \u003Ccode>--env\u003C\u002Fcode> and the server name, or the CLI reads the name as another env pair. The regex checks earn their place: a prompt-injected page can make the model call the tool with odd arguments, and unchecked input would let it write arbitrary text into your proxy username. For pages that need JavaScript, use option 1, or our \u003Ca href=\"\u002Fblog\u002Frotating-proxies-with-playwright\">Playwright rotating proxies guide\u003C\u002Fa> if you're building the browser layer yourself.\u003C\u002Fp>\n\n\u003Ch2>Cost control: agents burn bandwidth in ways scripts don't\u003C\u002Fh2>\n\u003Cp>Residential traffic is billed by the gigabyte, and an agent loads full pages, often several times per step. These controls make the biggest difference, roughly in order:\u003C\u002Fp>\n\u003Col>\n\u003Cli>Don't load what the model won't read. Images, video, fonts and ad scripts are most of a modern page's weight. Use \u003Ccode>text_mode=True\u003C\u002Fcode> and \u003Ccode>avoid_ads=True\u003C\u002Fcode> in Crawl4AI, the \u003Ccode>imagesEnabled=false\u003C\u002Fcode> switch or uBlock in browser-use, and a fetch tool instead of a browser when the page renders server-side.\u003C\u002Fli>\n\u003Cli>Cap retries in two places. Framework retries (\u003Ccode>max_failures\u003C\u002Fcode>, \u003Ccode>max_retries\u003C\u002Fcode>) and agent-level re-planning multiply each other. An agent that \"tries a different approach\" after a 403 often just reloads the same blocked page. Set \u003Ccode>max_steps\u003C\u002Fcode> low enough that a stuck run dies cheaply.\u003C\u002Fli>\n\u003Cli>Reuse contexts in stateful flows. A new browser context means fresh cookies, a fresh challenge and a fresh download of every cached asset. Within one task, keep the context (and the sticky IP) alive.\u003C\u002Fli>\n\u003Cli>Stop on block signals. Treat a CAPTCHA page, a 403 from a bot-management vendor, or a 429 as a terminal state that gets reported to a human. Don't let the agent retry its way past it. Our \u003Ca href=\"\u002Fblog\u002Fhandling-captchas-when-scraping\">CAPTCHA handling guide\u003C\u002Fa> has the reasoning for backing off.\u003C\u002Fli>\n\u003Cli>Measure per task, not per month. Log bytes per agent run. A sudden jump usually means a loop, not a bigger job.\u003C\u002Fli>\n\u003C\u002Fol>\n\n\u003Ch2>Failure modes worth designing for\u003C\u002Fh2>\n\u003Cp>Most agent proxy incidents come from one of four causes: a CAPTCHA loop, retry amplification, a session that silently changes IP, or credentials leaking into model context.\u003C\u002Fp>\n\u003Cul>\n\u003Cli>CAPTCHA loops. Vision-enabled agents will try to \"solve\" a challenge, fail, reload and try again. Detect challenge pages (known iframe hosts, titles such as \"Just a moment…\") and end the run. Answering challenges at scale isn't something a legitimate pipeline should do, and repeated failures from a residential IP hurt that IP's reputation for everyone using it.\u003C\u002Fli>\n\u003Cli>Retry amplification. Covered above: framework retries × proxy fallback lists × agent re-planning. Watch total attempts per URL, not just failures.\u003C\u002Fli>\n\u003Cli>Silent session breaks. A sticky session ends when its TTL runs out, and can end earlier if the upstream peer goes offline; the next request then leaves from a new IP. If a mid-flow request suddenly redirects to a login page, assume the IP changed. Restart the flow with a new session ID instead of letting the agent improvise.\u003C\u002Fli>\n\u003Cli>Credentials in the LLM context. Anything that reaches the model can end up in logs, traces, eval datasets or a prompt-injected exfiltration request. Keep proxy credentials in environment variables read by the browser or HTTP client. Don't put them in task strings, system prompts or tool output, and strip exception messages before returning them. Playwright MCP's \u003Ccode>secrets\u003C\u002Fcode> option can redact known strings from tool responses, but its own README calls that a convenience, not a security feature.\u003C\u002Fli>\n\u003C\u002Ful>\n\u003Cp>Before blaming the agent, test the proxy on its own: run the username variant you configured through the \u003Ca href=\"\u002Fproxy-checker\">proxy checker\u003C\u002Fa> and confirm the exit country and IP type are what you expect. For a broader comparison of IP types for agent workloads, see \u003Ca href=\"\u002Fblog\u002Fbest-proxies-ai-agents-llm-2026\">Best Proxies for AI Agents and LLM Web Data Collection\u003C\u002Fa>.\u003C\u002Fp>\n\n\u003Ch2>What this setup does not solve\u003C\u002Fh2>\n\u003Cp>A proxy changes where traffic comes from, not how it behaves. It won't make an agent pass behavioural bot detection, and it isn't permission to access a site that blocks automation in its robots.txt or terms. It won't make collecting personal data lawful either. If a site offers an API, a feed, or a signed-agent programme, those routes are usually cheaper and more reliable than any proxy configuration. Use residential IPs for what they're good at: correct geography, fair load distribution, and not inheriting a cloud range's reputation.\u003C\u002Fp>\n","Proxy Setup for AI Agents: browser-use & Crawl4AI | ProxyHat","Proxy setup for AI agents with working code: browser-use ProxySettings, Crawl4AI rotation and sticky sessions, a proxied MCP tool, and cost controls.","\u002Fblog\u002Fproxy-setup-for-ai-agents",null,"Proxy Setup for AI Agents: browser-use, Crawl4AI and MCP","Working proxy code for browser-use, Crawl4AI and an MCP server, plus when to use sticky IPs vs rotation and how to keep agent bandwidth in check.","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog-covers\u002Fen\u002Fproxy-setup-for-ai-agents-og.webp",[19,22,25,28,31],{"question":20,"answer":21},"How do I add a proxy to browser-use?","Pass proxy=ProxySettings(server=..., username=..., password=...) to Browser, importing ProxySettings from browser_use.browser. browser-use launches Chromium with --proxy-server and answers the proxy's auth challenge over CDP, so the credentials never reach the LLM. Use an HTTP proxy endpoint, because Chromium does not support SOCKS5 authentication.",{"question":23,"answer":24},"Should an AI agent use rotating or sticky proxies?","Use a sticky session for anything with state, such as login, multi-page forms or checkout, because many sites tie cookies and risk scores to the IP that opened the session. Use rotation for independent fetches like research reading or bulk crawling, where spreading requests keeps each IP under per-site limits.",{"question":26,"answer":27},"How do I rotate proxies in Crawl4AI?","Create a list of ProxyConfig objects, wrap it in RoundRobinProxyStrategy and pass it as proxy_rotation_strategy on CrawlerRunConfig. With a single backconnect gateway, make each ProxyConfig a different session username so each one has its own exit IP. Add proxy_session_id to pin one proxy for a multi-step sequence.",{"question":29,"answer":30},"Can I give Claude or another MCP assistant web access through a proxy?","Yes. Run Playwright MCP with a config file whose browser.launchOptions.proxy contains server, username and password, or write a small MCP tool with the Python SDK's MCPServer class that fetches pages through the proxy with httpx. In both cases keep the proxy credentials in environment variables or config files, not in prompts or tool output.",{"question":32,"answer":33},"Why do AI agents use so much proxy bandwidth?","Agents load full pages, often several times per step, and their retries stack up: framework retries, proxy fallback lists and the agent's own re-planning multiply each other. Blocking images, fonts and ads, capping max_steps and retries, reusing browser contexts and stopping at CAPTCHA pages cut most of the waste.",[35,36,37,38,39],"Agents on cloud VMs exit from datacenter ranges, so geo-accurate results and fair rate limits need a different egress.","Pin one sticky IP for stateful flows like login and checkout; rotate for independent fetches.","browser-use takes ProxySettings from browser_use.browser; Crawl4AI wants proxies per crawl on CrawlerRunConfig.","Crawl4AI fallback lists times max_retries can multiply page loads for one blocked URL; keep both small.","Keep proxy credentials out of prompts and tool output, and validate any model-supplied value that reaches the proxy username.",false,"2026-10-24T09:00:00+00:00","2026-10-24T09:00:20+00:00","2026-10-03T09:31:26+00:00","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog-covers\u002Fen\u002Fproxy-setup-for-ai-agents-master.webp","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog-covers\u002Fen\u002Fproxy-setup-for-ai-agents-card.webp",14,{"name":48,"slug":49,"bio":50,"avatar_url":14,"website_url":14,"social_links":14},"ProxyHat Team","proxyhat-team","The ProxyHat editorial team covers proxies, web scraping, and data extraction.",[52],{"id":53,"slug":54,"name":55,"description":14,"meta_title":56,"meta_description":57,"parent_id":14},4,"developer-guides","Developer Guides","Developer Guides | ProxyHat Blog","Code tutorials and SDK guides for integrating proxies into your applications.",[59,63,67,71],{"id":60,"slug":61,"name":62},1,"web-scraping","Web Scraping",{"id":64,"slug":65,"name":66},2,"residential-proxies","Residential Proxies",{"id":68,"slug":69,"name":70},9,"python","Python",{"id":72,"slug":73,"name":74},22,"playwright","Playwright",{"en":13,"de":76,"ko":77,"zh":78,"tr":79,"ru":80,"x-default":13},"\u002Fde\u002Fblog\u002Fproxy-einrichtung-fuer-ki-agenten","\u002Fko\u002Fblog\u002Fai-agent-proxy-seoljeong","\u002Fcn\u002Fblog\u002Fai-agent-daili-peizhi","\u002Ftr\u002Fblog\u002Fai-ajanlari-icin-proxy-kurulumu","\u002Fru\u002Fblog\u002Fnastrojka-proksi-dlya-ai-agentov",{"en":13,"de":76,"ko":77,"zh":78,"tr":79,"ru":80},31,[84,110,137,158],{"id":85,"slug":86,"title":87,"excerpt":88,"featured_image_url":89,"featured_image_alt":87,"card_image_url":90,"og_image_url":91,"published_at":92,"updated_at":93,"content_updated_at":43,"reading_time_minutes":46,"is_featured":40,"indexable":4,"views":94,"author":95,"categories":96,"tags":98},206,"camoufox-residential-proxies-python-guide","Camoufox with Residential Proxies: A Code-First Python Guide","How to run Camoufox, the C++-patched Firefox, behind residential proxies: current Python API, why geoip needs a sticky session, a fingerprint coherence checklist, and when Patchright or nodriver fits better.","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog-covers\u002Fen\u002Fcamoufox-residential-proxies-python-guide-master.webp","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog-covers\u002Fen\u002Fcamoufox-residential-proxies-python-guide-card.webp","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog-covers\u002Fen\u002Fcamoufox-residential-proxies-python-guide-og.webp","2026-10-13T09:00:00+00:00","2026-10-13T09:00:22+00:00",44,{"name":48,"slug":49,"bio":50,"avatar_url":14,"website_url":14,"social_links":14},[97],{"id":53,"slug":54,"name":55,"description":14,"meta_title":56,"meta_description":57,"parent_id":14},[99,100,104,108,109],{"id":60,"slug":61,"name":62},{"id":101,"slug":102,"name":103},6,"anti-detection","Anti-Detection",{"id":105,"slug":106,"name":107},21,"headless-browser","Headless Browser",{"id":68,"slug":69,"name":70},{"id":64,"slug":65,"name":66},{"id":111,"slug":112,"title":113,"excerpt":114,"featured_image_url":115,"featured_image_alt":14,"card_image_url":116,"og_image_url":117,"published_at":118,"updated_at":119,"content_updated_at":120,"reading_time_minutes":68,"is_featured":40,"indexable":4,"views":121,"author":122,"categories":123,"tags":127},24,"residential-vs-datacenter-proxies-scraping","Residential vs Datacenter Proxies for Scraping","Head-to-head comparison of residential and datacenter proxies for web scraping. Success rates, cost analysis, speed benchmarks, and a decision framework for your project.","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog\u002Fresidential-vs-datacenter-proxies-scraping-master.webp","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog\u002Fresidential-vs-datacenter-proxies-scraping-card.webp","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog\u002Fresidential-vs-datacenter-proxies-scraping-og.webp","2026-01-27T19:44:06+00:00","2026-07-19T03:13:07+00:00","2026-02-25T23:45:16+00:00",101,{"name":48,"slug":49,"bio":50,"avatar_url":14,"website_url":14,"social_links":14},[124],{"id":60,"slug":61,"name":62,"description":14,"meta_title":125,"meta_description":126,"parent_id":14},"Web Scraping Guides & Tips | ProxyHat Blog","Learn web scraping techniques, proxy strategies, and data extraction best practices.",[128,129,130,134],{"id":60,"slug":61,"name":62},{"id":64,"slug":65,"name":66},{"id":131,"slug":132,"name":133},3,"datacenter-proxies","Datacenter Proxies",{"id":53,"slug":135,"name":136},"proxy-comparison","Proxy Comparison",{"id":72,"slug":138,"title":139,"excerpt":140,"featured_image_url":141,"featured_image_alt":14,"card_image_url":142,"og_image_url":143,"published_at":144,"updated_at":119,"content_updated_at":145,"reading_time_minutes":146,"is_featured":40,"indexable":4,"views":147,"author":148,"categories":149,"tags":151},"rotating-proxies-with-playwright","Rotating Proxies with Playwright: Complete Developer Guide","Learn how to configure proxy rotation in Playwright — per-context proxies, stealth settings, geo-targeting, concurrent scraping, and production-ready patterns with code examples.","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog\u002Frotating-proxies-with-playwright-master.webp","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog\u002Frotating-proxies-with-playwright-card.webp","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog\u002Frotating-proxies-with-playwright-og.webp","2026-01-25T07:37:52+00:00","2026-10-03T08:21:20+00:00",11,370,{"name":48,"slug":49,"bio":50,"avatar_url":14,"website_url":14,"social_links":14},[150],{"id":53,"slug":54,"name":55,"description":14,"meta_title":56,"meta_description":57,"parent_id":14},[152,153,157],{"id":72,"slug":73,"name":74},{"id":154,"slug":155,"name":156},12,"sdk","SDK",{"id":60,"slug":61,"name":62},{"id":159,"slug":160,"title":161,"excerpt":162,"featured_image_url":163,"featured_image_alt":14,"card_image_url":164,"og_image_url":165,"published_at":166,"updated_at":119,"content_updated_at":167,"reading_time_minutes":168,"is_featured":40,"indexable":40,"views":169,"author":170,"categories":171,"tags":173},18,"proxy-rotation-strategies-scraping","Proxy Rotation Strategies for Large-Scale Scraping","Master the four key proxy rotation strategies: per-request, timed sticky sessions, failure-based, and geo-distributed. Code examples in Python, Node.js, and Go.","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog\u002Fproxy-rotation-strategies-scraping-master.webp","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog\u002Fproxy-rotation-strategies-scraping-card.webp","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog\u002Fproxy-rotation-strategies-scraping-og.webp","2026-01-21T14:25:21+00:00","2026-10-03T08:21:22+00:00",10,139,{"name":48,"slug":49,"bio":50,"avatar_url":14,"website_url":14,"social_links":14},[172],{"id":60,"slug":61,"name":62,"description":14,"meta_title":125,"meta_description":126,"parent_id":14},[174,175,179],{"id":60,"slug":61,"name":62},{"id":176,"slug":177,"name":178},23,"ip-rotation","IP Rotation",{"id":64,"slug":65,"name":66},[]]