Programmatic configuration·续6

Configuration for named exports declared by the Worker. Each entry's key is the exported class name; the value configures the export. - Construct entries with <code>exports.durableObject(...)</code>. - Declares Durable Object classes exported from this Worker. For more information about Durable Objects, see the documentation at <a href="https://developers.cloudflare.com/workers/learning/using-durable-objects">https://developers.cloudflare.com/workers/learning/using-durable-objects</a>. For reference, see <a href="https://developers.cloudflare.com/workers/wrangler/configuration/#durable-objects">https://developers.cloudflare.com/workers/wrangler/configuration/#durable-objects</a>. - Construct entries with <code>exports.workflow(...)</code>. - Declares Workflows defined by this Worker. For more information about Workflows, see the documentation at <a href="https://developers.cloudflare.com/workflows/">https://developers.cloudflare.com/workflows/</a>.

</details>

<details>

<summary>Counter: exports.durableObject({ (durableObject reference)</summary>

<code>durableObject</code>Builder<a href="#config-transfer-source-exports-durableobject-transferred">Link to durableObject</a>

<code>durableObject(options: DurableObjectTransferredExportOptions): DurableObjectTransferredExport;</code>

Transfer ownership of a Durable Object namespace to another Worker in the same account.

<details>

<summary>Options (2)</summary>

<dl>

<dt><code>state: "transferred"</code></dt> <dd></dd>

<dt><code>transferredTo: string</code></dt> <dd>The destination Worker. Must reference a Worker in the same account.</dd></dl></details>

</details>

<details>

<summary>state: "transferred", (state reference)</summary>

<code>state</code>Required<a href="#config-transfer-source-exports-durableobject-transferred-state">Link to state</a>

<code>state: "transferred"</code>

The type definition does not include a description.

</details>

<details>

<summary>transferredTo: "destination-worker", (transferredTo reference)</summary>

<code>transferredTo</code>Required<a href="#config-transfer-source-exports-durableobject-transferred-transferredto">Link to transferredTo</a>

<code>transferredTo: string</code>

The destination Worker. Must reference a Worker in the same account.

</details>

}),

},

},

});

Lifecycle changes take effect when a version is deployed, not when it is uploaded. Deploy an export-changing version to 100% of traffic before you split traffic with other versions. The platform rejects split deployments whose versions disagree about exports.

Attach a Container

Define a Container once. Reference it from a Durable Object export and add it to the top-level containers array.

Select a highlighted line to show its type and description below it.

cloudflare.config.ts

Expand allCopy

import { bindings, defineConfig, defineContainer, exports } from "cf/config";

import * as entrypoint from "./src/index.ts" with { type: "cf-worker" };

<details>

<summary>const imageProcessor = defineContainer({ (defineContainer reference)</summary>

<code>defineContainer</code>Function<a href="#config-container-definecontainer">Link to defineContainer</a>

<code>defineContainer<T extends ConfigInput<ContainerConfig>>(config: T): T;</code>

Defines a Container application that you can list in <code>containers</code> in <code>defineConfig()</code> or attach to a Durable Object export with its <code>container</code> option.

</details>

name: "image-processor",

image: { dockerfile: "./Dockerfile" },

instanceType: "lite",

maxInstances: 1,

});

<details>

<summary>export default defineConfig({ (defineConfig reference)</summary>

<code>defineConfig</code>Function<a href="#config-container-defineconfig">Link to defineConfig</a>

<code>defineConfig<T extends ConfigInput<CloudflareConfig>>(config: T): T;</code>

Defines the default export of <code>cloudflare.config.ts</code>. Pass a configuration object, a promise that resolves to one, or a function that receives the config context (<code>isPreview</code> and <code>mode</code>) and returns either.

<details>

<summary>Options (4)</summary>

<dl>

<dt><code>accountId?: string</code></dt> <dd>This is the ID of the account associated with your zone. It can also be specified through the <code>CLOUDFLARE_ACCOUNT_ID</code> environment variable.</dd>

<dt><code>complianceRegion?: "public" | "fedramp-high"</code></dt> <dd>The compliance boundary in which commands should operate. When omitted, this can be supplied through <code>CLOUDFLARE_COMPLIANCE_REGION</code>.</dd>

<dt><code>worker?: ConfigInput<WorkerConfig></code></dt> <dd>The Worker defined by this configuration.</dd>

<dt><code>containers?: ConfigInput<ContainerConfig>[]</code></dt> <dd>Container applications defined by this configuration.</dd></dl></details>

</details>

<details>

<summary>worker: { (worker reference)</summary>

<code>worker</code>Optional<a href="#config-container-cloudflareconfig-worker">Link to worker</a>

<code>worker?: ConfigInput<WorkerConfig></code>

The Worker defined by this configuration.

</details>

<details>

<summary>name: "image-worker", (name reference)</summary>

<code>name</code>Required<a href="#config-container-workerconfig-name">Link to name</a>

<code>name: string</code>

The name of your Worker.

</details>

<details>

<summary>entrypoint, (entrypoint reference)</summary>

<code>entrypoint</code>Optional<a href="#config-container-workerconfig-entrypoint">Link to entrypoint</a>

<code>entrypoint?: string | WorkerModule</code>

The entrypoint module that will be executed. May be either a path string (e.g. <code>"./src/index.ts"</code>) or a module namespace imported with the <code>cf-worker</code> import attribute.

</details>

<details>

<summary>compatibilityDate: "<COMPATIBILITY_DATE>", (compatibilityDate reference)</summary>

<code>compatibilityDate</code>Required<a href="#config-container-workerconfig-compatibilitydate">Link to compatibilityDate</a>

<code>compatibilityDate: string</code>

A date in the form yyyy-mm-dd, which will be used to determine which version of the Workers runtime is used. More details at <a href="https://developers.cloudflare.com/workers/configuration/compatibility-dates">https://developers.cloudflare.com/workers/configuration/compatibility-dates</a>

</details>

<details>

<summary>exports: { (exports reference)</summary>

<code>exports</code>Optional<a href="#config-container-workerconfig-exports">Link to exports</a>

<code>exports?: Record<string, Export></code>

Configuration for named exports declared by the Worker. Each entry's key is the exported class name; the value configures the export. - Construct entries with <code>exports.durableObject(...)</code>. - Declares Durable Object classes exported from this Worker. For more information about Durable Objects, see the documentation at <a href="https://developers.cloudflare.com/workers/learning/using-durable-objects">https://developers.cloudflare.com/workers/learning/using-durable-objects</a>. For reference, see <a href="https://developers.cloudflare.com/workers/wrangler/configuration/#durable-objects">https://developers.cloudflare.com/workers/wrangler/configuration/#durable-objects</a>. - Construct entries with <code>exports.workflow(...)</code>. - Declares Workflows defined by this Worker. For more information about Workflows, see the documentation at <a href="https://developers.cloudflare.com/workflows/">https://developers.cloudflare.com/workflows/</a>.

</details>

<details>

<summary>ImageProcessor: exports.durableObject({ (durableObject reference)</summary>

<code>durableObject</code>Builder<a href="#config-container-exports-durableobject-created">Link to durableObject</a>

<code>durableObject<TContainer extends ContainerDefinition | undefined = undefined>(options: DurableObjectCreatedExportOptions<TContainer>): DurableObjectCreatedExport<TContainer>;</code>

Declares a Durable Object class defined by this Worker. For more information about Durable Objects, see the documentation at <a href="https://developers.cloudflare.com/workers/learning/using-durable-objects">https://developers.cloudflare.com/workers/learning/using-durable-objects</a> For reference, see <a href="https://developers.cloudflare.com/workers/wrangler/configuration/#durable-objects">https://developers.cloudflare.com/workers/wrangler/configuration/#durable-objects</a>

<details>

<summary>Options (4)</summary>

<dl>

<dt><code>state?: "created"</code></dt> <dd></dd>

<dt><code>storage: "sqlite"</code></dt> <dd>Selects the SQLite-backed storage engine (recommended for new classes).</dd>

<dt><code>container?: TContainer</code></dt> <dd>Attach a Container application to this Durable Object by config reference.</dd>

<dt><code>storage: "legacy-kv"</code></dt> <dd>Selects the legacy key-value storage engine.</dd></dl></details>

</details>

<details>

<summary>storage: "sqlite", (storage reference)</summary>

<code>storage</code>Required<a href="#config-container-exports-durableobject-created-storage">Link to storage</a>

<code>storage: "sqlite" | "legacy-kv"</code>

Selects the SQLite-backed storage engine (recommended for new classes). Selects the legacy key-value storage engine.

</details>

<details>

<summary>container: imageProcessor, (container reference)</summary>

<code>container</code>Optional<a href="#config-container-exports-durableobject-created-container">Link to container</a>

<code>container?: TContainer</code>

Attach a Container application to this Durable Object by config reference.

</details>

}),

},

<details>

<summary>env: { (env reference)</summary>

<code>env</code>Optional<a href="#config-container-workerconfig-env">Link to env</a>

<code>env?: Record<string, Binding | false | null | undefined></code>

Bindings exposed on the Worker's <code>env</code> object. Construct entries with <code>bindings.kv(...)</code>, <code>bindings.r2(...)</code>, etc. Entries set to <code>false</code>, <code>null</code>, or <code>undefined</code> are omitted, which allows bindings to be included conditionally.

</details>

<details>

<summary>IMAGE_PROCESSOR: bindings.durableObject({ (durableObject reference)</summary>

<code>durableObject</code>Builder<a href="#config-container-bindings-durableobject-all">Link to durableObject</a>

<code>durableObject<TWorker$1 extends WorkerReference, TExportName$1 extends DurableObjectExportName<TWorker$1>>(options: DurableObjectBindingOptions<TWorker$1, TExportName$1>): DurableObjectBinding<TWorker$1, TExportName$1>;</code>

Binding to a Durable Object class. <code>worker</code> is the name or config of the Worker that defines the class; <code>exportName</code> is the exported class name. For reference, see <a href="https://developers.cloudflare.com/workers/wrangler/configuration/#durable-objects">https://developers.cloudflare.com/workers/wrangler/configuration/#durable-objects</a>

<details>

<summary>Options (2)</summary>

<dl>

<dt><code>worker: TWorker$1</code></dt> <dd>The name or config of the Worker that defines the Durable Object class.</dd>

<dt><code>exportName: TExportName$1</code></dt> <dd>The exported class name of the Durable Object.</dd></dl></details>

</details>

<details>

<summary>worker: "image-worker", (worker reference)</summary>

<code>worker</code>Required<a href="#config-container-bindings-durableobject-all-worker">Link to worker</a>

<code>worker: TWorker$1</code>

The name or config of the Worker that defines the Durable Object class.

</details>

<details>

<summary>exportName: "ImageProcessor", (exportName reference)</summary>

<code>exportName</code>Required<a href="#config-container-bindings-durableobject-all-exportname">Link to exportName</a>

<code>exportName: TExportName$1</code>

The exported class name of the Durable Object.

</details>

}),

},

},

<details>

<summary>containers: [imageProcessor], (containers reference)</summary>

<code>containers</code>Optional<a href="#config-container-cloudflareconfig-containers">Link to containers</a>

<code>containers?: ConfigInput<ContainerConfig>[]</code>

Container applications defined by this configuration.

</details>

});

Container names must be unique. Each Container can be linked to only one Durable Object export.

cf deploy applies supported Container application changes. cf workers versions create prepares images for Durable Object-managed Containers, but it does not apply Container applications.

Set account defaults

Set accountId and complianceRegion at the top level of the default export. Supported compliance regions are public and fedramp-high.

CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_COMPLIANCE_REGION take priority over these values. When neither the environment nor the configuration sets an account, cf uses the account it saved on an earlier command, or resolves one from your credentials. For the full order, refer to Select an account.

cf searches from the current directory toward the filesystem root and uses the nearest cloudflare.config.ts file.

When an API command reads account defaults, cf executes the module and resolves the default export. If the default export is a function, cf calls it with isPreview: false and the mode passed with --mode. Without --mode, the mode is undefined, while a Vite build of the same project uses production. cf deploy, cf workers versions create, and cf workers triggers deploy resolve the account the same way. Without --mode, they evaluate the configuration with an undefined mode, even when the Vite build used production. If accountId depends on the mode, pass --mode explicitly to every command.

API commands do not evaluate nested worker or containers factories, and they do not validate Worker fields. Syntax errors, import errors, and top-level runtime errors in the module still break them.

Select a mode

Pass --mode <NAME>, or -m <NAME>, to evaluate function-form configuration for a named mode. Project commands also pass the mode to the build:

cf build --mode staging
cf deploy --mode staging

When you omit --mode, the default depends on the tool that evaluates the configuration:

Command Default mode
cf dev with the Cloudflare Vite plugin development
cf build, cf deploy, and other commands that build with Vite production
Commands that build with Wrangler undefined
API commands, such as cf d1 list undefined

When cf runs a framework's own command, only Vite and Astro accept --mode. For other frameworks, the command stops with an error that says the detected command does not currently support --mode.

Build Output records the mode in its root config.json. To deploy an existing build with --prebuilt, pass the recorded mode. For the rule and examples, refer to Deploy a prebuilt build.

Was this helpful?

YesNo

On this page

Programmatic configuration·续6 - 图1Docs

{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/cf/projects/cloudflare-config/#page","headline":"Programmatic configuration","description":"Configure Workers projects with a typed cloudflare.config.ts file.","url":"https://developers.cloudflare.com/cf/projects/cloudflare-config/","inLanguage":"en","image":"https://developers.cloudflare.com/cf/projects/cloudflare-config/og.png?v=b3958a991af163a7","dateModified":"2026-09-29","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"}}


description: See how cloudflare.config.ts describes each part of an application, and what each typed field means. title: Configuration explorer image: https://developers.cloudflare.com/cf/projects/config-explorer/og.png?v=8877be631a13b653


Skip to content

Documentation Index
Fetch the complete documentation index at: https://developers.cloudflare.com/cf/llms.txt
Use this file to discover all available pages before exploring further.