Wrangler for AI agents
Cloudflare's Wrangler CLI for agents: run Workers locally, dry-run deploys, tail logs, and query D1, with auth and safety rules for coding agents.
What Wrangler does for an agent
Wrangler is Cloudflare's official command-line tool for the Workers developer platform. It runs a Worker locally, builds and deploys it, manages secrets, and works with bindings such as D1 databases, KV namespaces, and R2 buckets.
Cloudflare recommends installing it per project as a dev dependency, so an agent runs it with npx and every collaborator gets the same version from the lockfile.
Official site: developers.cloudflare.com/workers
Install Wrangler
The install commands from the official docs. Check it worked with npx wrangler --version.
npm install --save-dev wrangler
Signing in Wrangler for an agent
Locally, a human signs in once with an OAuth browser flow. In CI or a sandboxed agent, set an API token scoped to the account and the products the Worker needs.
npx wrangler whoami
npx wrangler login
Environment variables: CLOUDFLARE_API_TOKEN, CLOUDFLARE_ACCOUNT_ID. Set them in the agent's environment; never paste values into prompts or commit them.
What agents use Wrangler for
Example commands with placeholder names. Swap in your own project, app, or file names.
Run the Worker locally
npx wrangler dev
Long-running. Start it as a background process and stop it when the check is done.
Build without deploying
npx wrangler deploy --dry-run
Compiles and validates the Worker and its config without uploading anything.
Query a local D1 database
npx wrangler d1 execute my-db --local --command "SELECT name FROM sqlite_master WHERE type='table'"
Generate binding types
npx wrangler types
Stream production logs
npx wrangler tail
Streams until stopped. Run it with a timeout.
Safety rules for agents
Safe to run without asking
npx wrangler whoaminpx wrangler deploy --dry-runnpx wrangler tailnpx wrangler d1 execute my-db --local --command "SELECT ..."
Ask a human first
npx wrangler deploynpx wrangler secret put NAMEnpx wrangler d1 execute my-db --remote ...npx wrangler delete
- Treat wrangler deploy as a production release. Use --dry-run to check the build and leave the real deploy to a human or CI.
- Pass --local or --remote explicitly on D1 commands, and never run writes against --remote without approval.
- Use an API token limited to one account and the products the Worker uses, never a global API key.
AGENTS.md or CLAUDE.md snippet
Paste this into the instruction file your agent reads at the start of every session, then adjust the rules to your setup.
## Wrangler (wrangler) Use `wrangler` for developing, testing, and deploying Cloudflare Workers and their D1, KV, and R2 bindings. - Check it is installed with `npx wrangler --version`. If it is missing, ask before installing it. - Auth: a human signs wrangler in. Check with `npx wrangler whoami`; if it fails, stop and ask. Never run the login flow yourself, and never print tokens (CLOUDFLARE_API_TOKEN, CLOUDFLARE_ACCOUNT_ID). - Run without asking (read-only): `npx wrangler whoami`, `npx wrangler deploy --dry-run`, `npx wrangler tail`, `npx wrangler d1 execute my-db --local --command "SELECT ..."`. - Ask a human first (changes or deletes things): `npx wrangler deploy`, `npx wrangler secret put NAME`, `npx wrangler d1 execute my-db --remote ...`, `npx wrangler delete`. - Treat wrangler deploy as a production release. Use --dry-run to check the build and leave the real deploy to a human or CI. - Pass --local or --remote explicitly on D1 commands, and never run writes against --remote without approval. - Use an API token limited to one account and the products the Worker uses, never a global API key. - Prefer JSON output where the command supports it, and keep output short.
Wrangler or an MCP server?
An official MCP option exists. Cloudflare publishes official MCP servers for its platform, including documentation, Workers bindings, and observability. Use them when an agent needs account data without a local project checkout; use Wrangler when the agent is working inside the Worker's repository.
Rule of thumb: in a terminal agent that a human has signed in, the CLI is usually faster and cheaper in context. In a chat client without a shell, or when you want a fixed set of typed tools, use an MCP server.
Other Cloud & deploy tools
Wrangler questions
How do I install Wrangler?
Project dev dependency (recommended): npm install --save-dev wrangler. Check the install with npx wrangler --version, and see the Cloudflare docs for other platforms.
How does an AI agent authenticate Wrangler?
Locally, a human signs in once with an OAuth browser flow. In CI or a sandboxed agent, set an API token scoped to the account and the products the Worker needs. The agent can check the sign-in with npx wrangler whoami and should stop and ask if it fails.
Which Wrangler commands are safe for an agent to run?
Commands that only read state are safe to run without asking: npx wrangler whoami; npx wrangler deploy --dry-run; npx wrangler tail; npx wrangler d1 execute my-db --local --command "SELECT ...". Ask a human before anything that changes or deletes something: npx wrangler deploy; npx wrangler secret put NAME; npx wrangler d1 execute my-db --remote ...; npx wrangler delete.
Is there an MCP server for Wrangler?
Cloudflare publishes official MCP servers for its platform, including documentation, Workers bindings, and observability. Use them when an agent needs account data without a local project checkout; use Wrangler when the agent is working inside the Worker's repository.