Skip to content

Local development

You can build, run, and test your Worker code on your own local machine before deploying it to Cloudflare's network. This is made possible through Miniflare, a simulator that executes your Worker code in a local workerd ↗︎ process. workerd also powers the hosted Workers platform.

By default, your Worker's bindings connect to locally simulated resources, but can be configured to interact with the real, production resource with remote bindings.

Security considerations

Core concepts

Worker execution vs Bindings

When developing Workers, it's important to understand two distinct concepts:

  • Worker execution: Where your Worker code actually runs (on your local machine vs on Cloudflare's infrastructure).
  • Bindings: How your Worker interacts with Cloudflare resources (like KV namespaces, R2 buckets, D1 databases, Queues, Durable Objects, etc). In your Worker code, these are accessed via the env object (such as env.MY_KV).

Start a local development server

You can start a local development server using:

  1. The Cloudflare Workers CLI Wrangler, using the built-in wrangler dev command.
npx wrangler dev
  1. Vite ↗︎, using the Cloudflare Vite plugin.
npx vite dev

Both Wrangler and the Cloudflare Vite plugin use Miniflare under the hood, and are developed and maintained by the Cloudflare team. For guidance on choosing when to use Wrangler versus Vite, see our guide Choosing between Wrangler & Vite.

Inbound TCP and gRPC

To receive raw TCP connections locally, export a connect() handler and configure a TCP listener in wrangler.jsonc:

{
	"connect": [{ "protocol": "tcp", "port": 8788 }],
}
[[connect]]
protocol = "tcp"
port = 8_788

Connect TCP or gRPC clients to localhost:8788. The port comes from this configuration; exporting the handler alone does not create a listener.

Refer to Bidirectional gRPC with Workers and Containers for an example that uses the local TCP listener to test a gRPC server running in a Container.

Defaults

By default, running wrangler dev / vite dev (when using the Vite plugin) means that:

  • Your Worker code runs on your local machine.
  • Bindings in your Wrangler configuration use local resources where supported.
  • The local workerd runtime runs with TZ=UTC so that Date and Intl APIs inside your Worker observe UTC, matching the production Cloudflare runtime regardless of your machine's timezone.

Bindings during local development

Bindings are interfaces that allow your Worker to interact with various Cloudflare resources (like KV namespaces, R2 buckets, D1 databases, Queues, Durable Objects, etc). In your Worker code, these are accessed via the env object (such as env.MY_KV).

During local development, your Worker code interacts with these bindings using the exact same API calls (such as env.MY_KV.put()) as it would in a deployed environment. These local resources are initially empty, but you can populate them with data, as documented in Adding local data.

  • By default, bindings connect to local resource simulations where supported. Bindings with no local simulation — such as Workers AI, Vectorize, Media Transformations, and mTLS — require a remote binding connection. Refer to Supported bindings per development mode for the full breakdown.
  • You can override this default behavior and connect to the remote resource on a per-binding basis with remote bindings. This lets you connect to real, production resources while still running your Worker code locally.
  • Run wrangler dev --local to disable all remote binding connections. Bindings without local support do not work in this mode. The flag does not block outbound network requests from your Worker. Use it when you are offline or not logged in and your configuration would otherwise connect to a remote binding, such as Workers AI, Media Transformations, or a binding that supports remote: true and has it enabled. Without the flag, Wrangler can exit before starting the local server with Failed to start the remote proxy session.

Remote bindings

Remote bindings are bindings that are configured to connect to the deployed, remote resource during local development instead of the locally simulated resource. Remote bindings are supported by Wrangler, the Cloudflare Vite plugin, and the @cloudflare/vitest-plugin package. You can configure remote bindings by setting remote: true in the binding definition.

Example configuration

{
	"name": "my-worker",
	// Set this to today's date
	"compatibility_date": "2026-12-01",

	"r2_buckets": [
		{
			"bucket_name": "screenshots-bucket",
			"binding": "screenshots_bucket",
			"remote": true,
		},
	],
}
name = "my-worker"
# Set this to today's date
compatibility_date = "2026-12-01"

[[r2_buckets]]
bucket_name = "screenshots-bucket"
binding = "screenshots_bucket"
remote = true

With remote bindings, your Worker still runs locally. For a binding that supports remote connections, remote: true routes calls such as env.MY_KV.put() to the deployed resource. When you omit remote, each binding uses its default behavior. For example, KV uses its local simulation, while Workers AI uses the remote service.

Integration with environments

Remote Bindings work well together with Workers Environments. To protect production data, you can create a development or staging environment and specify different resources in your Wrangler configuration than you would use for production.

For example:

{
	"name": "my-worker",
	// Set this to today's date
	"compatibility_date": "2026-12-01",

	"env": {
		"production": {
			"r2_buckets": [
				{
					"bucket_name": "screenshots-bucket",
					"binding": "screenshots_bucket",
				},
			],
		},
		"staging": {
			"r2_buckets": [
				{
					"bucket_name": "preview-screenshots-bucket",
					"binding": "screenshots_bucket",
					"remote": true,
				},
			],
		},
	},
}
name = "my-worker"
# Set this to today's date
compatibility_date = "2026-12-01"

[[env.production.r2_buckets]]
bucket_name = "screenshots-bucket"
binding = "screenshots_bucket"

[[env.staging.r2_buckets]]
bucket_name = "preview-screenshots-bucket"
binding = "screenshots_bucket"
remote = true

Running wrangler dev -e staging (or CLOUDFLARE_ENV=staging vite dev) with the above configuration means that:

  • Your Worker code runs locally
  • All calls made to env.screenshots_bucket will use the preview-screenshots-bucket resource, rather than the production screenshots-bucket.

We recommend configuring specific bindings to connect to their remote counterparts. These services rely on Cloudflare's network infrastructure or have complex backends that are not simulated (or are only partially simulated) locally.

If you need to run automated tests completely offline without Cloudflare credentials or remote usage charges, refer to Offline and local binding support.

The following bindings are recommended to have remote: true in your Wrangler configuration:

Use a remote binding to access Cloudflare's managed Browser Run service. By default, local development runs Puppeteer, Playwright, Chrome DevTools Protocol (CDP), and .quickAction() calls against local Chrome with limited feature support.

{
	"browser": {
		"binding": "MY_BROWSER",
		"remote": true
	},
}
[browser]
binding = "MY_BROWSER"
remote = true

To utilize actual AI models deployed on Cloudflare's network for inference. There is no current local simulation for Workers AI.

{
	"ai": {
		"binding": "AI",
		"remote": true
	},
}
[ai]
binding = "AI"
remote = true

To connect to your production Vectorize indexes for accurate vector search and similarity operations. There is no current local simulation for Vectorize.

{
	"vectorize": [
		{
			"binding": "MY_VECTORIZE_INDEX",
			"index_name": "my-prod-index",
			"remote": true
		}
	],
}
[[vectorize]]
binding = "MY_VECTORIZE_INDEX"
index_name = "my-prod-index"
remote = true

Use the remote binding to transform videos while your Worker runs locally. Media Transformations has no local simulation.

{
	"media": {
		"binding": "MEDIA",
		"remote": true
	}
}
[media]
binding = "MEDIA"
remote = true

To verify that the certificate exchange and validation process work as expected. There is no current local simulation for mTLS bindings.

{
	"mtls_certificates": [
		{
			"binding": "MY_CLIENT_CERT_FETCHER",
			"certificate_id": "<YOUR_UPLOADED_CERT_ID>",
			"remote": true
			}
	]
}
[[mtls_certificates]]
binding = "MY_CLIENT_CERT_FETCHER"
certificate_id = "<YOUR_UPLOADED_CERT_ID>"
remote = true

To connect to a high-fidelity version of the Images API, and verify that all transformations work as expected. Local simulation for Cloudflare Images is limited with only a subset of features.

{
	"images": {
		"binding": "IMAGES" ,
		"remote": true
	}
}
[images]
binding = "IMAGES"
remote = true

Set remote: true to use your deployed Hyperdrive configuration while your Worker runs locally. To connect directly to a database instead, configure localConnectionString without remote: true.

Workers for Platforms users can configure remote: true in dispatch namespace binding definitions:

{
	"dispatch_namespaces": [
		{
			"binding": "DISPATCH_NAMESPACE",
			"namespace": "testing",
			"remote":true
		}
	]
}
[[dispatch_namespaces]]
binding = "DISPATCH_NAMESPACE"
namespace = "testing"
remote = true

This allows you to run your dynamic dispatch Worker locally, while connecting it to your remote dispatch namespace binding. This allows you to test changes to your core dispatching logic against real, deployed user Workers.

Unsupported remote bindings

Certain bindings are not supported for remote connections (i.e. with remote: true) during local development. These will always use local simulations or local values.

Wrangler ignores remote: true on these bindings and usually warns about an unexpected field. Version Metadata ignores it without a warning. Queues does not warn either and continues routing to the local queue. Refer to Supported bindings per development mode.

  • Durable Objects: Enabling remote connections for Durable Objects may be supported in the future, but currently will always run locally. However, using Durable Objects in combination with remote bindings is possible. Refer to Using remote resources with Durable Objects and Workflows below.
  • Workflows: Enabling remote connections for Workflows may be supported in the future, but currently will only run locally. However, using Workflows in combination with remote bindings is possible. Refer to Using remote resources with Durable Objects and Workflows below.
  • Containers: Container instances run locally through your local Docker-compatible engine during development and do not support remote binding connections.
  • Environment Variables (vars): Environment variables are intended to be distinct between local development and deployed environments. They are easily configurable locally (such as in a .dev.vars file or directly in Wrangler configuration).
  • Secrets: Like environment variables, secrets are expected to have different values in local development versus deployed environments for security reasons. Use .dev.vars for local secret management.
  • Static Assets Static assets are always served from your local disk during development for speed and direct feedback on changes.
  • Version Metadata: Since your Worker code is running locally, version metadata (like commit hash, version tags) associated with a specific deployed version is not applicable or accurate.
  • Queues: Producer bindings send messages to the local queue, even if you set remote: true.
  • Rate Limiting: Local development sessions typically should not share or affect rate limits of your deployed Workers. Rate limiting logic should be tested against local simulations.

Using remote resources with Durable Objects and Workflows

While Durable Object and Workflow bindings cannot currently be remote, you can still use them during local development and have them interact with remote resources.

There are two recommended patterns for this:

  • Local Durable Objects/Workflows with remote bindings:

    When you enable remote bindings in your Wrangler configuration, your locally running Durable Objects and Workflows can access remote resources. This allows such bindings, although run locally, to interact with remote resources during local development.

  • Accessing remote Durable Objects/Workflows via service bindings:

    To interact with remote Durable Object or Workflow instances, deploy a Worker that defines those. Then, in your local Worker, configure a remote service binding pointing to the deployed Worker. Your local Worker will be then able to interact with the remote deployed Worker, which in turn can communicate with the remote Durable Objects/Workflows. Using this method, you can create a communication channel via the remote service binding, effectively using the deployed Worker as a proxy interface to the remote bindings during local development.

Important Considerations

  • Cloudflare Access: If your Worker is protected by Cloudflare Access, Wrangler must authenticate with Access when connecting to remote bindings. Refer to Connect to Access-protected Workers.
  • Data modification: Operations (writes, deletes, updates) on bindings connected remotely will affect your actual data in the targeted Cloudflare resource (be it preview or production).
  • Billing: Interactions with remote Cloudflare services through these connections will incur standard operational costs for those services (such as KV operations, R2 storage/operations, AI requests, D1 usage).
  • Network latency: Expect network latency for operations on these remotely connected bindings, as they involve communication over the internet.

Connect to Access-protected Workers

If your Worker is protected by Cloudflare Access, Wrangler must authenticate with Access when connecting to your remote bindings. This applies whether Access protects the Worker itself, all Workers in the account, a workers.dev hostname, a Custom Domain, or another hostname or path that routes to the Worker.

There are two ways you can authenticate against Access:

  • Interactive login (local development): If you have a policy defined that accepts user login, then Wrangler launches the interactive cloudflared access login flow in your browser. No additional setup is required beyond being signed in to the correct account. If the policy only allows service token authentication, Wrangler will skip the interactive flow and throw an error indicating that service token credentials are required.
  • Service token (CI / non-interactive environments): In CI/CD pipelines and other non-interactive contexts, or where the policy only allows service token authentication, Wrangler cannot trigger the interactive flow via the browser. Authentication must be via a Cloudflare Access service token instead. If you do not configure a service token in a non-interactive environment, Wrangler will throw an error rather than attempting the interactive flow.

To set up service token authentication:

  1. Create a service token.

    In the Cloudflare dashboard, go to Zero Trust > Access > Service Auth > Service Tokens and create a new token. Refer to Service tokens for the full reference. You will be shown a Client ID and a Client Secret — save them somewhere safe, as the secret is not shown again.

  2. Add a Service Auth policy to the Access application that protects your Worker.

    Open the existing Access application that already protects the Worker or the hostname you use for remote bindings, and attach a new policy with:

    • Action: Service Auth
    • Include: The service token you created, or "Any Access Service Token" if you want to allow any service token to access the Worker.
  3. Expose the credentials to Wrangler.

    Set the CLOUDFLARE_ACCESS_CLIENT_ID and CLOUDFLARE_ACCESS_CLIENT_SECRET system environment variables in the environment that runs Wrangler:

    export CLOUDFLARE_ACCESS_CLIENT_ID=<CLIENT_ID>
    export CLOUDFLARE_ACCESS_CLIENT_SECRET=<CLIENT_SECRET>

    In CI, store the values as secrets and expose them as environment variables to the step that runs Wrangler.

Programmatic API

For tooling authors integrating remote bindings with Miniflare, refer to the Remote bindings proxy API in the Wrangler API reference (startRemoteProxySession, unstable_convertConfigBindingsToStartWorkerBindings, and maybeStartOrUpdateRemoteProxySession).

wrangler dev --remote (Legacy)

Separate from Miniflare-powered local development, Wrangler also offers a fully remote development mode via wrangler dev --remote. Remote development is not supported in the Vite plugin.

npx wrangler dev --remote

During remote development, all of your Worker code is uploaded to a temporary preview environment on Cloudflare's infrastructure, and changes to your code are automatically uploaded as you save.

When using remote development, all bindings automatically connect to their remote resources. Unlike local development, you cannot configure bindings to use local simulations - they will always use the deployed resources on Cloudflare's network.

When to use Remote development

  • For most development tasks, the most efficient and productive experience will be local development along with remote bindings when needed.
  • You may want to use wrangler dev --remote for testing features or behaviors that are highly specific to Cloudflare's network and cannot be adequately simulated locally or tested via remote bindings.

Considerations

  • Iteration is significantly slower than local development due to the upload/deployment step for each change.

Limitations

  • When you run a remote development session using the --remote flag, a limit of 50 routes per zone is enforced. Learn more in Workers platform limits.
  • Python Workers do not support the --remote flag. Use remote bindings instead.

Was this helpful?