Worker Deploy Command, Environments, Secrets, and CI
How to publish edge Workers with Wrangler or cf CLI: login, deploy, secrets, staging vs production, Pages uploads, and CI dry-runs.
This page summarises Cloudflare Developers documentation on taking a Worker (or a framework project built for Workers) from your machine or CI pipeline to a live URL on *.workers.dev, a custom domain, or Cloudflare Pages.
wrangler deploy: the default publish command
Section titled “wrangler deploy: the default publish command”Most tutorials end with the same step: run wrangler deploy (often as npx wrangler deploy) from the project directory. Cloudflare describes Wrangler as bundling your code, uploading it, and releasing the application.
Wrangler has built-in support for bundling, uploading, and releasing your Cloudflare Workers application. To do this, run npx wrangler deploy, which will build and deploy your code.
— Cloudflare, Build a QR code generator
After a successful run, you typically get a URL such as <YOUR_WORKER>.<YOUR_SUBDOMAIN>.workers.dev. The Workers CLI guide states that you can deploy to a *.workers.dev subdomain or a custom domain, and that Wrangler prompts you to set up a subdomain during the first publish if none is configured.
First upload: wrangler deploy, not versions upload
Section titled “First upload: wrangler deploy, not versions upload”For a new Workers project, the first publication must use C3 or wrangler deploy. Using wrangler versions upload on the very first upload fails.
You must use C3 or wrangler deploy the first time you create a new Workers project. Using wrangler versions upload the first time you upload a Worker will fail.
— Cloudflare, Deployment management
What a basic agent deploy does
Section titled “What a basic agent deploy does”For Agents, a single deploy step performs several operations at once:
This:
Bundles your code
Uploads to Cloudflare
Provisions the Agent’s Durable Object namespace storage
Makes it live on *.workers.dev— Cloudflare, Agent configuration
wrangler login: sign in before you publish
Section titled “wrangler login: sign in before you publish”If Wrangler is not authenticated, deploy opens a browser flow. Several AI and Vectorize guides use the same pattern: log in, allow Wrangler access, then deploy.
Log in with your Cloudflare account:
npx wrangler login
Deploy your Worker to make it accessible on the Internet:
npx wrangler deploy
— Cloudflare, AI SDK
The Staff Directory tutorial adds that wrangler whoami confirms login; otherwise Wrangler prompts you to create an API key for authenticated requests from your computer.
The Turso + Workers tutorial notes that the first npx wrangler deploy may launch a browser to sign in and grant permissions, then prints bindings and the published URL.
npm run deploy: build then publish
Section titled “npm run deploy: build then publish”Framework guides (React, Nuxt, Angular, Gatsby, and others) usually expose a deploy script that builds and publishes in one step. The pattern is the same whether you use npm, yarn, or pnpm.
Your project can be deployed to a *.workers.dev subdomain or a Custom Domain, from your own machine or from any CI/CD system, including Cloudflare’s own.
The following command will build and deploy your project. If you’re using CI, ensure you update your “deploy command” configuration appropriately.
npm run deploy
yarn run deploy
pnpm run deploy— Cloudflare, Angular on Workers
Automatic configuration adds typical package.json scripts:
{ "scripts": { "deploy": "wrangler deploy", "preview": "wrangler dev", "cf-typegen": "wrangler types" }}Running npx wrangler deploy in an existing repo may trigger automatic configuration: Wrangler detects the framework, shows the config it will apply, and asks you to confirm before changing files and deploying (Deploy an existing project).
Vite + Worker split build
Section titled “Vite + Worker split build”For React + Vite on Workers, run the framework build first; the dist folder holds client assets and Worker code plus an output wrangler.json. Deploy then uses that generated config:
Run the deploy command to deploy your application to Cloudflare.
npx wrangler deploy
This command will automatically use the output wrangler.json that was included in the build output.
— Cloudflare, React + Vite
Deploy environments: --env staging and production secrets
Section titled “Deploy environments: --env staging and production secrets”When the Wrangler config defines environments, you target them explicitly:
# Deploy to stagingnpx wrangler deploy --env staging
# Deploy to productionnpx wrangler deploy --env productionSecrets are per environment:
npx wrangler secret put OPENAI_API_KEY --env stagingnpx wrangler secret put OPENAI_API_KEY --env production— Cloudflare, Agent configuration
Workers CI/CD build configuration lists deploy commands you can set in CI, including:
| Example command | Purpose |
|---|---|
npx wrangler deploy --assets ./public/ |
Deploy Worker with static assets from a directory |
npx wrangler deploy --env staging |
Deploy a named Wrangler environment |
npx wrangler deploy --containers-rollout=immediate |
Container rollout strategy for this deploy |
npx wrangler deploy --containers-rollout=none |
Deploy Worker only; skip container image build/push and rollout |
wrangler secret put: set production credentials after or before deploy
Section titled “wrangler secret put: set production credentials after or before deploy”Tutorials deploy the Worker first, then push secrets with wrangler secret put. Examples from the cluster:
| Secret | Typical use | Source |
|---|---|---|
ANTHROPIC_API_KEY |
Sandbox / AI executors | Analyze data with AI, Code review bot |
GITHUB_TOKEN |
Private repos, bots | Automated testing pipeline, Code review bot |
OPENAI_API_KEY |
AI tutorials | Create fine-tuned model with R2, Slack agent |
WEBHOOK_URL / WEBHOOK_SECRET |
Webhooks | BGP anomalies, Test webhooks locally |
The fine-tuned ChatGPT tutorial requires setting OPENAI_API_KEY before deploy in that walkthrough. The code review bot sets several secrets after npx wrangler deploy, then updates the GitHub webhook payload URL to the live Worker URL.
For Deploy to Cloudflare buttons, if no deploy script exists, the template defaults to npx wrangler deploy. You can chain migrations in deploy, for example:
{ "scripts": { "build": "astro build", "deploy": "npm run db:migrations:apply && wrangler deploy", "db:migrations:apply": "wrangler d1 migrations apply DB_BINDING --remote" }}wrangler pages deploy: static sites and Pages Functions
Section titled “wrangler pages deploy: static sites and Pages Functions”Cloudflare Pages projects may use the dashboard or Wrangler. From a built output directory:
wrangler pages deploy blog-frontend— Cloudflare, Build an API with Pages Functions
Direct Upload with CI uses:
CLOUDFLARE_ACCOUNT_ID=<ACCOUNT_ID> npx wrangler pages deploy <DIRECTORY> --project-name=<PROJECT_NAME>The localize a website tutorial sets pages_build_output_dir in the Wrangler file and uses "deploy": "wrangler pages deploy" in package.json.
C3 can optionally deploy immediately after project creation: you sign in if needed and the CLI provides a deployment URL.
Custom domain vs workers.dev only
Section titled “Custom domain vs workers.dev only”Deploy a real-time chat application documents routes in Wrangler (pattern, zone_id, or custom_domain: true) and dashboard paths under Workers & Pages → Triggers → Add Custom Domain.
To restrict access to a custom hostname, the AI agent wrapper tutorial sets workers_dev = false, adds routes with custom_domain = true, runs wrangler deploy, and recommends turning off workers.dev and Preview URLs so only the custom domain works.
Workers for Platforms user Workers with static assets use:
npx wrangler deploy --name <USER_WORKER_NAME> --dispatch-namespace <NAMESPACE_NAME>Artifacts mention wrangler deploy --dispatch_namespace <DISPATCH_NAMESPACE> for user Workers in a dispatch namespace.
cf deploy and cf build: alternative CLI workflow
Section titled “cf deploy and cf build: alternative CLI workflow”The newer cf CLI separates build validation from upload. From Develop, build, and deploy:
cf deploybuilds the project, validates Build Output, resolves your credentials and account, uploads a new Worker Version, and deploys it— Cloudflare, Develop, build, and deploy
Sign in with cf auth login or CLOUDFLARE_API_TOKEN before deploy (Deploy your first Worker (cf)).
Useful flags:
| Option | Purpose |
|---|---|
--dry-run |
Build and validate without API requests or upload |
--prebuilt |
Deploy existing .cloudflare/output/v0/ without rebuilding |
--mode <MODE> |
Must match the mode recorded at build time (e.g. Vite production) |
--secrets-file <PATH> |
Upload secrets with the version |
--containers-rollout <STRATEGY> |
immediate, gradual, or none |
--dry-runsends no API requests and needs no credentials, so you can validate a project before you sign in.— Cloudflare, Develop, build, and deploy
Use cf in CI recommends cf build, then cf deploy --prebuilt --mode production --dry-run on pull requests, and deploy only on pushes to main with repository secrets CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID.
Migrate a Wrangler project suggests validating with cf dev, cf build, and cf deploy --dry-run before cf auth login and cf deploy.
CI/CD: GitHub Actions, GitLab, and Workers Builds
Section titled “CI/CD: GitHub Actions, GitLab, and Workers Builds”External CI/CD for Workers supports GitHub Actions and GitLab CI/CD. The official GitHub Actions example uses cloudflare/wrangler-action@v4 with CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID on push to main.
GitLab CI/CD notes replacing npm run deploy with npx wrangler deploy in pipeline scripts.
For cf-based repos, the cf CI guide workflow runs npm ci, npx cf build, dry-run deploy on every PR, and production deploy only when secrets are available—so fork PRs can still run the dry run.
Set your platform deploy command to match your package.json (for example npm run deploy or npx wrangler deploy --env production) as described in Workers CI/CD build configuration.
Deploy from dashboard, Playground, and one-click templates
Section titled “Deploy from dashboard, Playground, and one-click templates”You can deploy without a local terminal in several places:
- Workers Playground: review and deploy; first-time onboarding if not signed in.
- Workers for Platforms get started: editor Deploy Worker creates an isolated script reachable at
/<script-name>on your Worker URL. - Prometheus exporter: one-click Deploy to Cloudflare Workers, then
wrangler secret put CLOUDFLARE_API_TOKEN.
create-cloudflare (C3) optionally deploys after configuration; deployment is optional at prompt time.
Common mistakes and limits after deploy
Section titled “Common mistakes and limits after deploy”HTTP 523 on first workers.dev push
Section titled “HTTP 523 on first workers.dev push”Several guides (Workers CLI, Rust Workers, RAG tutorial) warn:
When pushing to your *.workers.dev subdomain for the first time, you may see 523 errors while DNS is propagating. These errors should resolve themselves after a minute or so.
— Cloudflare, Build a Retrieval Augmented Generation (RAG) AI
Sandbox containers need warm-up time
Section titled “Sandbox containers need warm-up time”After first deploy of container-backed Workers (Analyze data with AI, AI code executor, Workers AI code interpreter):
Wait 2-3 minutes after first deployment for container provisioning.
— Cloudflare, Analyze data with AI
Check status with npx wrangler containers list where documented.
Unauthenticated public URLs
Section titled “Unauthenticated public URLs”The AI code interpreter get-started cautions:
The Worker does not authenticate requests. Anyone with the URL can send questions and use your Workers AI allowance. Authenticate callers before you share the URL.
— Cloudflare, Build an AI code interpreter
Test the live Worker
Section titled “Test the live Worker”VPC and API gateway examples deploy with npx wrangler deploy then curl the published URL (private API, private database, route across private services). Workers Cache shows verifying caching with curl -I and the Cf-Cache-Status header after deploy.
Redeploy and teardown
Section titled “Redeploy and teardown”Updating code is the same command again: npx wrangler deploy. The real-time chat tutorial redeploys after migration changes to remove Durable Object classes; full removal uses dashboard Manage Service → Delete.
How to check this on your site
Section titled “How to check this on your site”-
Run
npx wrangler whoamiorcf auth login/ setCLOUDFLARE_API_TOKENso your CLI can reach your account (Staff Directory, cf projects). -
From the project root, run
npx wrangler deployor yourpackage.jsondeploy script (for examplenpm run deploy) and note the URL Wrangler prints (Workers get started guide). -
If the app needs API keys or webhooks, confirm required names with
wrangler secret put <NAME>(and--envif you use staging/production) as in your tutorial—then hit the live URL withcurlor a browser (private database example). -
In the Cloudflare dashboard (Workers & Pages), open your Worker, check Deployments / version history, and confirm the latest version matches what you just uploaded (KV get started).
-
You can check automatically in Answerwell (our tool): https://answerwell.org/workspace
Report an error or ask a question
Section titled “Report an error or ask a question”If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact sentence you are asking about, and we will correct or clarify it.