How to Build AI Agents That Browse the Web with Cloudflare Kitesurf
AI agents are evolving from chatbots that answer questions to systems that can navigate the web, fill forms, and complete tasks on your behalf. But there is a problem: conventional browsers like Chrome were designed for humans, not software. They consume too much memory, worry about visual rendering, and cost too much when every agent needs its own instance.
On August 7, Cloudflare launched Kitesurf, a browser built specifically for AI agents. It runs entirely on Cloudflare serverless Workers platform, uses significantly less CPU and memory than Chromium for common agentic tasks, and is available for free in beta. This tutorial walks you through building your first AI agent that browses the web using Kitesurf and Browser Run.
What You Will Build
By the end of this tutorial, you will have a working AI agent that can navigate to a website, extract structured data, and take a screenshot using Kitesurf as the browser engine. You will understand how to control the browser programmatically and combine it with LLMs for autonomous decision-making.
What You Need
- A Cloudflare account (free tier works)
- Basic JavaScript or TypeScript knowledge
- Node.js version 18 or later
- About 15 minutes
Step 1: Enable Browser Run
Log into your Cloudflare dashboard and navigate to Workers and Pages. Find Browser Run in the left sidebar and click Enable. The free plan includes about 500 sessions per month, enough for development. Note your Account ID from the right sidebar under the API section. Create an API token with Workers and Browser Run permissions under My Profile and API Tokens.
Step 2: Set Up Your Project
Create a new directory and initialize a Node.js project with npm init -y. Install the packages: npm install @cloudflare/browser-run puppeteer. The @cloudflare/browser-run package handles the WebSocket connection to Kitesurf, while Puppeteer provides the familiar browser automation API.
Step 3: First Agent Script
Create agent.js. Connect to Kitesurf via Browser Run using your account ID and API token. Open a new page, navigate to a URL, extract the page title, take a screenshot, and close the browser. Set your credentials as environment variables: CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_API_TOKEN.
Step 4: Extract Structured Data
Build a scrapeProduct function that navigates to a product page, evaluates the DOM to extract the title, price, and description, and returns a JSON object. This pattern works for any structured data extraction task.
Step 5: AI Agent Loop
Combine Kitesurf with an LLM. The agent reads the page content, asks the AI to decide what to do next, and executes the decision. The AI can choose to click a link, extract more data, or return the final result. This creates an autonomous browsing agent that makes decisions without human intervention.
Step 6: Quick Actions
Kitesurf also supports Quick Actions, simple HTTP endpoints that return screenshots, PDFs, markdown, or JSON data with a single API call. No code deployment needed. Just POST to the endpoint with the URL and get your result back.
Common Problems
Connection timeouts: Check that your API token has Browser Run permissions and that you are not exceeding the free tier concurrency limit of five simultaneous sessions.
Pages not rendering: JavaScript-heavy sites may need longer wait times. Use waitUntil networkidle0 or add explicit delays.
Token costs: The free tier handles about 500 sessions per month. Paid plans start at a few dollars per thousand sessions.
Security and Privacy
Kitesurf runs on Cloudflare global network, not on your machine. Pages are loaded inside Cloudflare isolated Workers sandbox. This means you can run automation without exposing your local IP or browser fingerprint. However, treat any extracted data with the same care as data you would browse yourself.
Final Result
You now have a working AI agent that can browse the web, extract data, take screenshots, and make decisions using an LLM, all powered by Kitesurf. The code runs in about 15 minutes from scratch and costs nothing on the free tier. Kitesurf gives developers a browser that focuses on what AI agents actually need: fast, cheap, scalable web access.