AIニュース最前線
最新ニュースAI日報Hacker日報週報動画AIツールトレンド企業

AIニュース最前線

世界中のAI最新情報を日本語で毎時更新

最新ニュース日報トレンド企業プレミアムRSS
© 2026 ainew.jp特定商取引法に基づく表記
ニュース一覧元記事を開く
Cloudflare Blog·2026年4月13日 22:08·約7分で読める

Dynamic WorkersにおけるDurable Objects:各AI生成アプリに独自のデータベースを提供

#Serverless AI#Cloudflare Workers#Durable Objects#AI Agent Development#Dynamic Code Execution
TL;DR

CloudflareはDynamic Workersで生成されたAIアプリに永続的な状態管理を提供するため、Durable Objectsとの統合方法を提案し、動的コード実行と固定ストレースプロビジョニングの技術的課題について解説している。

AI深層分析2026年4月13日 23:44
4
重要/ 5段階
深度40%
4
関連度30%
4
実用性20%
4
革新性10%
3

キーポイント

1

Dynamic Workersの基盤技術

コンテナより軽量な「isolates」を採用し、コードをオンデマンドで安全なサンドボックスに高速読み込み可能。

2

AI生成アプリの永続化ニーズ

単発実行からユーザー対話型UIを持つ長期状態を保持するAI生成アプリへの用途拡大。

3

Durable Objectsとの統合案

Cloudflareの高速SQLiteストレース「Durable Objects」を動的コードに提供し、ゼロレイテンシのデータアクセスを実現。

4

動的プロビジョニングの技術的壁

通常必要とされるWrangler設定や名前空間バインディングが、API経由で実行されないDynamic Workersの特性と衝突する課題。

5

Dynamic WorkersとDOストレージの互換性問題

Dynamic WorkerはCloudflare APIを介さずに実行されるため、従来のDurable Objectストレージのプロビジョニングや名前空間の指定と互換性がありません。

6

リソース管理と制御の必要性

エージェントやユーザーが無制限にDOを作成・利用できるのは望ましくなく、作成数の制限、ログ出力、観測性、課金などの管理機能が必要となります。

7

Durable Object Facetsによる解決策

オープンベータで提供されるFacets機能により、メインのDO内でエージェントコードをDynamic Workerとして動的に読み込み、「ファセット」として独立したSQLiteデータベースを使用しながら運用できます。

影響分析・編集コメントを表示

影響分析

本記事は、AIエージェントが生成するコードの実行環境を「使い捨て」から「永続状態付き」へ移行させるためのCloudflare独自のアーキテクチャ提案を示している。Dynamic WorkersとDurable Objectsの組み合わせにより、低レイテンシかつセキュアなAIアプリ開発が可能になる一方、動的コードと静的リソースプロビジョニングの統合には新たな抽象化レイヤーが必要となる。これはサーバーレスAI開発のパターンを定義する重要な一歩であり、Cloudflareエコシステム内のAIインフラ競争力を高める。

編集コメント

記事が途中で切れているものの、AI生成コードの「状態管理」をどうサーバーレス環境で解決するかという核心課題を的確に捉えている。Cloudflareが提案するDurable Objectsとの連携は、今後台頭するAgentic AIのインフラ標準を形作る可能性を秘めている。

数週間前、私たちはDynamic Workersを発表しました。これはWorkersプラットフォームの新機能で、Workerコードを安全なサンドボックスに動的にロードできます。Dynamic Worker Loader APIは本質的に、Workersが当初から基盤としてきた基本的なコンピュート分離のプリミティブ、すなわちコンテナではなくアイソレートへの直接アクセスを提供します。アイソレートはコンテナよりもはるかに軽量で、その結果、1/10のメモリ使用量で100倍高速にロードできます。非常に効率的であるため、「使い捨て」として扱うことが可能です。数行のコードを実行するために起動し、その後破棄します。セキュア版のeval()のようなものです。

Dynamic Workersには多くの用途があります。最初の発表では、ツール呼び出しの代替としてAIエージェントが生成したコードを実行する方法に焦点を当てました。このユースケースでは、AIエージェントがユーザーの要求に応じて数行のコードを記述し、それを実行することでアクションを実行します。このコードは単回使用を意図しており、一度だけタスクを実行し、実行後すぐに破棄されます。

しかし、AIにより永続性の高いコードを生成させたい場合はどうでしょうか?AIにカスタムUIを持つ小さなアプリケーションを構築させ、ユーザーが操作できるようにしたい場合は?そのアプリケーションに長寿命の状態を持たせたい場合は?ただし、もちろん、それは安全なサンドボックス内で実行させたいでしょう。

これを実現する一つの方法は、Dynamic Workersを使用し、そのWorkerにストレージへのアクセス権を与えるRPC APIを単純に提供することです。バインディングを使用すれば、Dynamic WorkerにリモートのSQLデータベース(Cloudflare D1でバックアップされているものや、Hyperdriveを介してアクセスするPostgresデータベースなど、選択は自由です)を指し示すAPIを与えることができます。

しかし、Workersにはこのユースケースに完璧に適合する、独特で極めて高速なストレージタイプも存在します:Durable Objectsです。Durable Objectは特殊な種類のWorkerで、一意の名前を持ち、名前ごとにグローバルに一つのインスタンスが存在します。そのインスタンスにはSQLiteデータベースが接続されており、Durable Objectが実行されるマシンのローカルディスク上に存在します。これにより、ストレージアクセスは驚異的に高速になります:実質的にレイテンシはゼロです。

おそらく、あなたが本当に望んでいるのは、AIにDurable Object用のコードを書かせ、そのコードをDynamic Worker内で実行することでしょう。

しかし、どうすればよいのでしょうか?

これは奇妙な問題を提起します。通常、Durable Objectsを使用するには以下を行う必要があります:

  1. DurableObjectを拡張するクラスを記述する。
  2. Workerのメインモジュールからそれをエクスポートする。
  3. Wrangler設定で、このクラスに対してストレージをプロビジョニングするよう指定する。これにより、受信リクエストを処理するためのあなたのクラスを指すDurable Objectネームスペースが作成される。
  4. あなたのネームスペースを指すDurable Objectネームスペースバインディングを宣言する(またはctx.exportsを使用する)、そしてそれを使用してあなたのDurable Objectにリクエストを行う。

これは自然にはDynamic Workersに拡張できません。まず、明白な問題があります:コードが動的です。Cloudflare APIを一切呼び出さずに実行します。しかし、Durable ObjectストレージはAPIを通じてプロビジョニングされる必要があり、ネームスペースは実装クラスを指している必要があります。あなたのDynamic Workerを指すことはできません。

しかし、より深い問題があります:仮にどうにかしてDurable ObjectネームスペースをDynamic Workerに直接指し示すように設定できたとして、そうしたいでしょうか?あなたのエージェント(またはユーザー)が、Durable Objectsでいっぱいのネームスペース全体を作成できるようにしたいですか?世界中に広がる無制限のストレージを使用できるようにしたいですか?

おそらく望まないでしょう。ある程度の制御を望むはずです。作成するオブジェクトの数を制限したり、少なくとも追跡したりしたいかもしれません。おそらく単一のオブジェクトに制限したいでしょう(「バイブコーディング」された個人用アプリにはおそらく十分です)。ロギングやその他のオブザーバビリティ、メトリクス、課金などを追加したいかもしれません。

これらすべてを行うために、あなたが本当に望むのは、これらのDurable Objectsへのリクエストが最初にあなたのコードに送られ、そこで全ての「物流管理」を行った後、リクエストをエージェントのコードに転送することです。すべてのDurable Objectの一部として実行されるスーパーバイザーを書きたいのです。

解決策: Durable Object Facets

本日、この問題を解決する機能をオープンベータとしてリリースします。

image
image

Durable Object Facetsを使用すると、Durable Objectクラスを動的にロードしてインスタンス化し、ストレージとして使用するSQLiteデータベースを提供できます。Facetsでは:

  1. まず、あなたが記述したクラスを指す通常のDurable Objectネームスペースを作成します。
  2. そのクラス内で、エージェントのコードをDynamic Workerとしてロードし、それを呼び出します。
  3. Dynamic Workerのコードは、直接Durable Objectクラスを実装できます。つまり、文字通りextends DurableObjectと宣言されたクラスをエクスポートします。
  4. あなたはそのクラスを、自身のDurable Objectの「ファセット」としてインスタンス化します。

ファセットは独自のSQLiteデータベースを取得し、通常のDurable ObjectストレージAPIを使用してそれを利用できます。このデータベースはスーパーバイザーのデータベースとは別ですが、両者は同じDurable Object全体の一部として一緒に保存されます。

仕組み

以下は、Durable Objectクラスを動的にロードして実行するアプリケーションプラットフォームの、シンプルで完全な実装例です。

javascript
import { DurableObject } from "cloudflare:workers";

// この例では、静的なアプリケーションコードを使用しますが、
// 実際にはこれはAI(あるいは人間のユーザーさえも)によって
// 生成される可能性があります。
const AGENT_CODE = `
  import { DurableObject } from "cloudflare:workers";

  // 呼び出された回数を記憶して返すシンプルなアプリ
  export class App extends DurableObject {
    fetch(request) {
      // ここでは簡略化のためstorage.kvを使用していますが、
      // storage.sqlも利用可能です。どちらもSQLiteでバックアップされています。
      let counter = this.ctx.storage.kv.get("counter") || 0;
      ++counter;
      this.ctx.storage.kv.put("counter", counter);

      return new Response("You've made " + counter + " requests.\\n");
    }
  }
`;

// Ap

FacetsはDynamic Workersの機能であり、Workers Paidプランのユーザーはベータ版をすぐに利用できます。

Dynamic WorkersとFacetsについて詳しくは、ドキュメントをご覧ください。

原文を表示

A few weeks ago, we announced Dynamic Workers, a new feature of the Workers platform which lets you load Worker code on-the-fly into a secure sandbox. The Dynamic Worker Loader API essentially provides direct access to the basic compute isolation primitive that Workers has been based on all along: isolates, not containers. Isolates are much lighter-weight than containers, and as such, can load 100x faster using 1/10 the memory. They are so efficient, they can be treated as "disposable": start one up to run a few lines of code, then throw it away. Like a secure version of eval().

Dynamic Workers have many uses. In the original announcement, we focused on how to use them to run AI-agent-generated code as an alternative to tool calls. In this use case, an AI agent performs actions at the request of a user by writing a few lines of code and executing them. The code is single-use, intended to perform one task one time, and is thrown away immediately after it executes.

But what if you want an AI to generate more persistent code? What if you want your AI to build a small application with a custom UI the user can interact with? What if you want that application to have long-lived state? But of course, you still want it to run in a secure sandbox.

One way to do this would be to use Dynamic Workers, and simply provide the Worker with an RPC API that gives it access to storage. Using bindings, you could give the Dynamic Worker an API that points back to your remote SQL database (perhaps backed by Cloudflare D1, or a Postgres database you access through Hyperdrive — it's up to you).

But Workers also has a unique and extremely fast type of storage that may be a perfect fit for this use case: Durable Objects. A Durable Object is a special kind of Worker that has a unique name, with one instance globally per name. That instance has a SQLite database attached, which lives on local disk on the machine where the Durable Object runs. This makes storage access ridiculously fast: there is effectively zero latency.

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.

But how?

This presents a weird problem. Normally, to use Durable Objects you have to:

Write a class extending DurableObject.

Export it from your Worker's main module.

Specify in your Wrangler config that storage should be provision for this class. This creates a Durable Object namespace that points at your class for handling incoming requests.

Declare a Durable Object namespace binding pointing at your namespace (or use ctx.exports), and use it to make requests to your Durable Object.

This doesn't extend naturally to Dynamic Workers. First, there is the obvious problem: The code is dynamic. You run it without invoking the Cloudflare API at all. But Durable Object storage has to be provisioned through the API, and the namespace has to point at an implementing class. It can't point at your Dynamic Worker.

But there is a deeper problem: Even if you could somehow configure a Durable Object namespace to point directly at a Dynamic Worker, would you want to? Do you want your agent (or user) to be able to create a whole namespace full of Durable Objects? To use unlimited storage spread around the world?

You probably don't. You probably want some control. You may want to limit, or at least track, how many objects they create. Maybe you want to limit them to just one object (probably good enough for vibe-coded personal apps). You may want to add logging and other observability. Metrics. Billing. Etc.

To do all this, what you really want is for requests to these Durable Objects to go to your code first, where you can then do all the "logistics", and then forward the request into the agent's code. You want to write a supervisor that runs as part of every Durable Object.

Solution: Durable Object Facets

Today we are releasing, in open beta, a feature that solves this problem.

imageimage

Durable Object Facets allow you to load and instantiate a Durable Object class dynamically, while providing it with a SQLite database to use for storage. With Facets:

First you create a normal Durable Object namespace, pointing to a class you write.

In that class, you load the agent's code as a Dynamic Worker, and call into it.

The Dynamic Worker's code can implement a Durable Object class directly. That is, it literally exports a class declared as extends DurableObject.

You are instantiating that class as a "facet" of your own Durable Object.

The facet gets its own SQLite database, which it can use via the normal Durable Object storage APIs. This database is separate from the supervisor's database, but the two are stored together as part of the same overall Durable Object.

How it works

Here is a simple, complete implementation of an app platform that dynamically loads and runs a Durable Object class:

import { DurableObject } from "cloudflare:workers";

// For the purpose of this example, we'll use this static

// application code, but in the real world this might be generated

// by AI (or even, perhaps, a human user).

const AGENT_CODE = `

import { DurableObject } from "cloudflare:workers";

// Simple app that remembers how many times it has been invoked

// and returns it.

export class App extends DurableObject {

fetch(request) {

// We use storage.kv here for simplicity, but storage.sql is

// also available. Both are backed by SQLite.

let counter = this.ctx.storage.kv.get("counter") || 0;

++counter;

this.ctx.storage.kv.put("counter", counter);

return new Response("You've made " + counter + " requests.\\n");

}

}

`;

// AppRunner is a Durable Object you write that is responsible for

// dynamically loading applications and delivering requests to them.

// Each instance of AppRunner contains a different app.

export class AppRunner extends DurableObject {

async fetch(request) {

// We've received an HTTP request, which we want to forward into

// the app.

// The app itself runs as a child facet named "app". One Durable

// Object can have any number of facets (subject to storage limits)

// with different names, but in this case we have only one. Call

// this.ctx.facets.get() to get a stub pointing to it.

let facet = this.ctx.facets.get("app", async () => {

// If this callback is called, it means the facet hasn't

// started yet (or has hibernated). In this callback, we can

// tell the system what code we want it to load.

// Load the Dynamic Worker.

let worker = this.#loadDynamicWorker();

// Get the exported class we're interested in.

let appClass = worker.getDurableObjectClass("App");

return { class: appClass };

});

// Forward request to the facet.

// (Alternatively, you could call RPC methods here.)

return await facet.fetch(request);

}

// RPC method that a client can call to set the dynamic code

// for this app.

setCode(code) {

// Store the code in the AppRunner's SQLite storage.

// Each unique code must have a unique ID to pass to the

// Dynamic Worker Loader API, so we generate one randomly.

this.ctx.storage.kv.put("codeId", crypto.randomUUID());

this.ctx.storage.kv.put("code", code);

}

#loadDynamicWorker() {

// Use the Dynamic Worker Loader API like normal. Use get()

// rather than load() since we may load the same Worker many

// times.

let codeId = this.ctx.storage.kv.get("codeId");

return this.env.LOADER.get(codeId, async () => {

// This Worker hasn't been loaded yet. Load its code from

// our own storage.

let code = this.ctx.storage.kv.get("code");

return {

compatibilityDate: "2026-04-01",

mainModule: "worker.js",

modules: { "worker.js": code },

globalOutbound: null, // block network access

}

});

}

}

// This is a simple Workers HTTP handler that uses AppRunner.

export default {

async fetch(req, env, ctx) {

// Get the instance of AppRunner named "my-app".

// (Each name has exactly one Durable Object instance in the

// world.)

let obj = ctx.exports.AppRunner.getByName("my-app");

// Initialize it with code. (In a real use case, you'd only

// want to call this once, not on every request.)

await obj.setCode(AGENT_CODE);

// Forward the request to it.

return await obj.fetch(req);

}

}

In this example:

AppRunner is a "normal" Durable Object written by the platform developer (you).

Each instance of AppRunner manages one application. It stores the app code and loads it on demand.

The application itself implements and exports a Durable Object class, which the platform expects is named App.

AppRunner loads the application code using Dynamic Workers, and then executes the code as a Durable Object Facet.

Each instance of AppRunner is one Durable Object composed of two SQLite databases: one belonging to the parent (AppRunner itself) and one belonging to the facet (App). These databases are isolated: the application cannot read AppRunner's database, only its own.

To run the example, copy the code above into a file worker.js, pair it with the following wrangler.jsonc, and run it locally with npx wrangler dev.

// wrangler.jsonc for the above sample worker.

{

"compatibility_date": "2026-04-01",

"main": "worker.js",

"migrations": [

{

"tag": "v1",

"new_sqlite_classes": [

"AppRunner"

]

}

],

"worker_loaders": [

{

"binding": "LOADER",

},

],

}

Start building

Facets are a feature of Dynamic Workers, available in beta immediately to users on the Workers Paid plan.

Check out the documentation to learn more about Dynamic Workers and Facets.

この記事をシェア

関連記事

Cloudflare Blog★42026年3月27日 22:00

抽象構文木(AST)を使用してWorkflowsコードを視覚的図に変換する方法

Cloudflareは、Workflowsのコードを抽象構文木(AST)で解析し、ダッシュボード上で視覚的図として表示する機能を追加した。これにより、開発者はアプリケーションの構造を可視化できるようになった。

AWS Machine Learning Blog★32026年6月3日 02:31

Amazon Nova 2 Lite を用いた物体検出

AWS は、小規模チームでも高コストなインフラ構築を回避できるよう、Amazon Bedrock で利用可能な多モーダル基盤モデル「Amazon Nova 2 Lite」を発表し、自然言語による物体検出機能を強化した。

Cloudflare Blog★42026年5月13日 22:00

Browser Run が Cloudflare コンテナ上で稼働し、高速化とスケーラビリティが向上

開発チームは Browser Run を Cloudflare のコンテナ基盤に再構築しました。これにより、1 分間に最大 60 ブラウザを起動可能になり、並行実行数は 120 に達し、以前より 4 倍の性能向上を実現しています。また、クイックアクションの応答時間が 50% 以上短縮され、信頼性も高まりました。

ニュース一覧に戻る元記事を読む