Agent Builder v2 is in open beta. Features and limitations described here are subject to change.
env, and you can inspect database tables and stored objects in Control Center.
These features apply to Workers (index.js, no root Dockerfile). A container does not receive env.DATABASE or env.STORAGE—use Vault and an external service instead.
Add a database
When you deploy a Worker, WRITER attaches one D1 database for that agent asenv.DATABASE. Every environment on the agent uses that same database.
- Deploy a Worker with
index.jsat the archive root and no rootDockerfile. - Query from
fetchwith prepared statements and.bind()for user input:
- Store JSON as
TEXTwithJSON.stringify/JSON.parsewhen you need arrays or objects.
Apply database migrations
Put schema files in a top-levelmigrations/ directory so WRITER applies them at deploy time.
- Add
*.sqlfiles such as0001_init.sqland0002_add_status.sql(lexicographic order). - Keep each file safe to run again (
IF NOT EXISTS, or anALTERthat checks whether the change is already there).
SQL that lives only under a nested directory, such as
backend/migrations/, fails the deploy. Move those files to a top-level migrations/ directory. Nested SQL next to a real root migrations/ directory is ignored.Add object storage
When you deploy a Worker, WRITER attaches one R2 bucket for that agent asenv.STORAGE. Every environment on the agent uses that same bucket. Put and get objects from fetch. Store the object key in the database when you need a file reference, and serve files through your Worker instead of persisting a public URL.
Add a queue
Declare queue producers (and consumers, if you need them) in a root Wrangler config, and omit a rootDockerfile. A root Wrangler config that includes queues uses the Wrangler deploy path, which binds only the resources you declare—also declare DATABASE and STORAGE if your Worker still needs them.
fetch, and handle batches in queue when you declare a consumer. This example inserts into the tickets table from Add a database—apply that migration first, or the insert fails with no such table:
Add a cron job
Add cron expressions undertriggers.crons in a root Wrangler config. WRITER applies those schedules on deploy. Handle them in scheduled. A config that only declares triggers.crons stays on the default Worker path, so env.DATABASE and env.STORAGE are still attached automatically—you don’t need to declare them here:
Package and deploy the Worker
Build TypeScript or npm packages locally intoindex.js. The platform does not install packages or compile Worker source. Include index.js and, if you use a schema, top-level migrations/. Omit a root Dockerfile.
Browse database and object storage in the Data tab
After a Worker environment deploys successfully, open that environment in Control Center and select the Data tab. You can inspect and edit the same database tables and object-storage folders your Worker uses.- Open the agent in Control Center and select the environment (for example Development).
- Select the Data tab.
- Choose a table or a folder in the resource tree to open it in the viewer.

Match binding names for local development
Keep a root Wrangler config so localwrangler dev uses the same names WRITER injects. If the file declares D1 or R2, the binding names must be DATABASE and STORAGE or the deploy fails. Resource ids in the file are for local use only—WRITER creates the real database and bucket.
Troubleshoot bindings
Use this table when a Worker deploy fails on packaging or binding names, or when the Data tab has nothing to show after a successful deploy.Next steps
- Get started with Agent Builder v2 to create an agent, deploy a snapshot, and set Vault secrets.
- Learn about Agent Builder v2 for supported frameworks, environments, and limitations.
- Call your agent via API to exercise the endpoints you added.
- Agent Builder v2 observability to review request performance, events, usage, and logs.