wrangler secret command manages encrypted secrets for your Cloudflare Workers.
secret put
Create or update a secret for a Worker.The variable name to be accessible in the Worker
Options
Name of the Worker. If not specified, it will default to the name specified in your Wrangler config file
Environment to use
Example
Notes
- If running in an interactive terminal, Wrangler will prompt you to enter the secret value securely
- If not in an interactive terminal, the secret value is read from stdin
- Secrets are encrypted and stored securely by Cloudflare
- In Workers code, secrets are accessed via the
envobject:env.API_KEY
secret delete
Delete a secret from a Worker.The variable name to be accessible in the Worker
Options
Name of the Worker. If not specified, it will default to the name specified in your Wrangler config file
Environment to use
Example
Notes
- Requires confirmation before deletion
- Once deleted, the secret cannot be recovered
- The Worker will no longer have access to this secret after deletion
secret list
List all secrets for a Worker.Options
Name of the Worker. If not specified, it will default to the name specified in your Wrangler config file
Environment to use
The format to print the secrets in
Example
Output
The list command returns secret names only (not values, as they are encrypted):secret bulk
Upload multiple secrets for a Worker at once.The file of key-value pairs to upload, as JSON in form
{"key": "value", ...} or .env file in the form KEY=VALUE. If omitted, Wrangler expects to receive input from stdin rather than a fileOptions
Name of the Worker. If not specified, it will default to the name specified in your Wrangler config file
Environment to use
Example
File Formats
JSON Format:secrets.json
.env.production
Notes
- Both JSON and .env file formats are supported
- Existing secrets with the same names will be updated
- All other existing secrets will be preserved
- The operation is atomic - either all secrets are updated or none are
Complete Workflow Example
Best Practices
- Never commit secrets to version control - Use
.gitignoreto exclude secret files - Use different secrets for different environments - Maintain separate secrets for production, staging, and development
- Rotate secrets regularly - Update sensitive credentials periodically
- Use bulk upload for multiple secrets - More efficient than adding secrets one by one
- Store backup copies securely - Keep encrypted backups of your secrets in a secure password manager
- Limit secret access - Only grant access to secrets for team members who need them
Secrets vs Environment Variables
| Feature | Secrets | Environment Variables |
|---|---|---|
| Storage | Encrypted at rest | Plain text in config |
| Visibility | Hidden in dashboard | Visible in dashboard |
| Use case | API keys, passwords, tokens | Non-sensitive config values |
| Access method | env.SECRET_NAME | env.VAR_NAME |
| Management | wrangler secret commands | Wrangler config file or dashboard |
- API keys and tokens
- Database passwords
- Encryption keys
- OAuth client secrets
- Any sensitive credential
- Feature flags
- Non-sensitive configuration
- Public API endpoints
- Version numbers