Configuration philosophy
workerd’s configuration follows several key principles:- Capability-based security: Workers have no access to external resources by default. You must explicitly declare bindings to grant access to specific resources.
- No global namespaces: Resources are not accessed by name. Instead, workers receive JavaScript API objects (bindings) that point to specific resources.
- Composability: By changing config alone, you can fully control which resources a worker connects to, without modifying code.
- Service-oriented: Each workerd instance is composed of multiple named services that can be workers, network access, external servers, or disk directories.
Basic structure
A workerd configuration file has three main components:- Services: Named services that define workers and other capabilities
- Sockets: Network listeners that expose services
- Extensions: Optional capabilities provided to all workers
Cap’n Proto text format
workerd configuration files use Cap’n Proto text format, which provides:- Strong typing: The schema validates your configuration at parse time
- Structured data: Complex nested structures with unions and optional fields
- File embedding: Use
embed "file.js"to include external files directly - Comments: Use
#for single-line comments
Common syntax patterns
Top-level configuration
TheConfig struct accepts these fields:
List of named services defined by this server. Service names are private and used only within this config file for references and logging.
List of sockets on which the server will listen and the services exposed through them.
Extensions that provide capabilities to all workers. Extensions are typically prepared separately and late-linked with the app.
Command-line flags to pass to V8, like
--expose-gc. Use with caution as V8 flags can have unpredictable effects and are not guaranteed to be stable between V8 versions.List of gates which are enabled. These are used to gate features/changes in workerd.
Console and stdio logging configuration options.
Command-line usage
Once you have a configuration file, you can run workerd with:Overriding configuration
You can override certain configuration values from the command line:Compiling standalone binaries
You can compile your configuration and code into a standalone binary:Multiple configurations
A single.capnp file can contain multiple configuration constants. Specify which one to use:
The “internet” service
If you don’t define a service called “internet”, one is created implicitly:fetch() function unless you specify a different globalOutbound service in your worker configuration.
The default “internet” service blocks private network addresses to prevent SSRF attacks.
Next steps
Services
Learn about the different types of services
Workers
Configure worker services
Sockets
Set up network listeners
Bindings
Grant capabilities through bindings