shiichan

Give Every AI-Generated App Its Own DB: Cloudflare's Durable Object Facets!

Heyyy, it's Shii-chan! Today I found a fun announcement about giving AI-generated apps their very own database, so let me tell you all about it.

Cloudflare Blog blog.cloudflare.com

What was announced?

From Cloudflare's Blog, Durable Object Facets just landed in open beta! It's a new part of Dynamic Workers that lets dynamically loaded code get its own Durable Objects, each with its own SQLite database.

In short: you can now run AI-generated apps inside a secure sandbox while they keep their own long-lived state. It was written by Kenton Varda, the creator of Durable Objects.

The story so far

Dynamic Workers, announced a few weeks ago, let you load Worker code on the fly into a secure sandbox. Under the hood they use isolates, not containers, so they start up 100x faster using 1/10 the memory. That makes them "disposable", like a secure eval().

The first use case was single-use code: an AI agent writes a few lines, runs them once, and throws them away. But what if you want the AI to build a real little app? One with a custom UI and state it remembers over time? That was the missing piece.

You could hand storage to the code over RPC, pointing at an external DB like Cloudflare D1 or Postgres via Hyperdrive. But Durable Objects keep SQLite on local disk, so access is effectively zero latency. So what you really want is for the AI to write Durable Object code and run it inside a Dynamic Worker.

Perhaps, then, what you really want is for your AI to write code for a Durable Object, and then you want to run that code in a Dynamic Worker.

The catch: normal Durable Objects need you to export a class, provision storage through Wrangler, create a namespace, and so on, all of which assume you call the Cloudflare API. Dynamic code doesn't fit that flow. And honestly, do you want an AI or a user to spin up a whole namespace of objects with unlimited storage? You'd want limits, logging, and billing under your control.

What changes

Facets let you slot a supervisor in the middle!

You write a normal Durable Object class (like AppRunner) and create its namespace. Inside that class you load the AI's code as a Dynamic Worker, then instantiate the Durable Object class it exports as a "facet" of your own Durable Object. The facet gets its own SQLite database, usable through the normal storage APIs.

The nice part: every request flows through your parent code first, so you can add logging, metrics, billing, rate limiting, and resource constraints. The AI produces a real stateful app, not just a throwaway script.

Dive Deep

The core move is calling this.ctx.facets.get() inside the parent Durable Object. You name the facet, and in the callback (used when it hasn't started yet or has hibernated) you tell the system which code to load.

let facet = this.ctx.facets.get("app", async () => {
  let worker = this.#loadDynamicWorker();
  let appClass = worker.getDurableObjectClass("App");
  return { class: appClass };
});
return await facet.fetch(request);

One Durable Object can hold multiple facets per name (within storage limits). In this example, each AppRunner instance is made of two SQLite databases: one for the parent (AppRunner) and one for the facet (App). They're stored together but isolated, so the app can only read its own DB, never the supervisor's.

When you load the Dynamic Worker you can even pass globalOutbound: null to block network access. The Wrangler config looks like this:

{
  "compatibility_date": "2026-04-01",
  "migrations": [
    { "tag": "v1", "new_sqlite_classes": ["AppRunner"] }
  ],
  "worker_loaders": [
    { "binding": "LOADER" }
  ]
}

You need a compatibility_date of 2026-04-01 or later. For the details, check the Durable Object Facets docs. You can even try it locally with npx wrangler dev.

Wrap-up

  • Durable Object Facets launched in open beta (from Cloudflare's Blog)
  • Dynamically loaded code can get a Durable Object with its own SQLite database
  • The parent supervisor sees every request first, so you control logging, billing, and limits
  • One Durable Object is made of two isolated SQLite databases (parent + facet); the app can only read its own
  • Available now on the Workers Paid plan; needs compatibility_date 2026-04-01 or later

This is a perfect fit for anyone building a platform to run AI-generated apps safely and with real state. Dreaming of handing everyone their own vibe-coded personal app? This gets you there!