{"id":240,"date":"2026-02-20T00:00:00","date_gmt":"2026-02-20T00:00:00","guid":{"rendered":"https:\/\/wordpress.securinsight.ca\/index.php\/2026\/02\/20\/agents-workers-cloudflare-codemode-v0-1-0-a-new-runtime-agnostic-modular-architecture\/"},"modified":"2026-02-20T00:00:00","modified_gmt":"2026-02-20T00:00:00","slug":"agents-workers-cloudflare-codemode-v0-1-0-a-new-runtime-agnostic-modular-architecture","status":"publish","type":"post","link":"https:\/\/wordpress.securinsight.ca\/index.php\/2026\/02\/20\/agents-workers-cloudflare-codemode-v0-1-0-a-new-runtime-agnostic-modular-architecture\/","title":{"rendered":"Agents, Workers &#8211; @cloudflare\/codemode v0.1.0: a new runtime agnostic modular architecture"},"content":{"rendered":"<p>The <a href=\"https:\/\/www.npmjs.com\/package\/@cloudflare\/codemode\" target=\"_blank\"><code>@cloudflare\/codemode<\/code><\/a> package has been rewritten into a modular, runtime-agnostic SDK.<\/p>\n<p><a href=\"https:\/\/blog.cloudflare.com\/code-mode\/\" target=\"_blank\">Code Mode<\/a> enables LLMs to write and execute TypeScript that orchestrates your tools, instead of calling them one at a time. This can (and does) yield significant token savings, reduces context window pressure and improves overall model performance on a task.<\/p>\n<p>The new <code>Executor<\/code> interface is runtime agnostic and comes with a prebuilt <code>DynamicWorkerExecutor<\/code> to run generated code in a <a href=\"https:\/\/developers.cloudflare.com\/workers\/runtime-apis\/bindings\/worker-loader\/\">Dynamic Worker Loader<\/a>.<\/p>\n<h4>Breaking changes<\/h4>\n<ul>\n<li>Removed <code>experimental_codemode()<\/code> and <code>CodeModeProxy<\/code> \u2014 the package no longer owns an LLM call or model choice<\/li>\n<li>New import path: <code>createCodeTool()<\/code> is now exported from <code>@cloudflare\/codemode\/ai<\/code><\/li>\n<\/ul>\n<h4>New features<\/h4>\n<ul>\n<li><strong><code>createCodeTool()<\/code><\/strong> \u2014 Returns a standard AI SDK <code>Tool<\/code> to use in your AI agents.<\/li>\n<li><strong><code>Executor<\/code> interface<\/strong> \u2014 Minimal <code>execute(code, fns)<\/code> contract. Implement for any code sandboxing primitive or runtime.<\/li>\n<\/ul>\n<h4><code>DynamicWorkerExecutor<\/code><\/h4>\n<p>Runs code in a <a href=\"https:\/\/developers.cloudflare.com\/workers\/runtime-apis\/bindings\/worker-loader\/\">Dynamic Worker<\/a>. It comes with the following features:<\/p>\n<ul>\n<li><strong>Network isolation<\/strong> \u2014 <code>fetch()<\/code> and <code>connect()<\/code> blocked by default (<code>globalOutbound: null<\/code>) when using <code>DynamicWorkerExecutor<\/code><\/li>\n<li><strong>Console capture<\/strong> \u2014 <code>console.log\/warn\/error<\/code> captured and returned in <code>ExecuteResult.logs<\/code><\/li>\n<li><strong>Execution timeout<\/strong> \u2014 Configurable via <code>timeout<\/code> option (default 30s)<\/li>\n<\/ul>\n<h4>Usage<\/h4>\n<ul>\n<li>\n<p>JavaScript<\/p>\n<div>\n<div>\n<figure>\n<pre data-language=\"js\"><code class=\"language-js\"><div><div><span>import <\/span><span>{<\/span><span><span> <\/span><span>createCodeTool<\/span><span> <\/span><\/span><span>}<\/span><span> from <\/span><span>\"@cloudflare\/codemode\/ai\"<\/span><span>;<\/span><\/div><\/div><div><div><span>import <\/span><span>{<\/span><span><span> <\/span><span>DynamicWorkerExecutor<\/span><span> <\/span><\/span><span>}<\/span><span> from <\/span><span>\"@cloudflare\/codemode\"<\/span><span>;<\/span><\/div><\/div><div><div><span>import <\/span><span>{<\/span><span><span> <\/span><span>streamText<\/span><span> <\/span><\/span><span>}<\/span><span> from <\/span><span>\"ai\"<\/span><span>;<\/span><\/div><\/div><div><div>\n<\/div><\/div><div><div><span>const<\/span><span> <\/span><span>executor<\/span><span> <\/span><span>=<\/span><span> <\/span><span>new<\/span><span> <\/span><span>DynamicWorkerExecutor<\/span><span>(<\/span><span>{<\/span><span> loader<\/span><span>:<\/span><span> <\/span><span>env<\/span><span>.<\/span><span>LOADER<\/span><span> <\/span><span>}<\/span><span>)<\/span><span>;<\/span><\/div><\/div><div><div><span>const<\/span><span> <\/span><span>codemode<\/span><span> <\/span><span>=<\/span><span> <\/span><span>createCodeTool<\/span><span>(<\/span><span>{<\/span><span> tools<\/span><span>:<\/span><span> <\/span><span>myTools<\/span><span>,<\/span><span> <\/span><span>executor<\/span><span> <\/span><span>}<\/span><span>)<\/span><span>;<\/span><\/div><\/div><div><div>\n<\/div><\/div><div><div><span>const<\/span><span> <\/span><span>result<\/span><span> <\/span><span>=<\/span><span> <\/span><span>streamText<\/span><span>(<\/span><span>{<\/span><\/div><\/div><div><div><span>  <\/span><span>model<\/span><span>,<\/span><\/div><\/div><div><div><span><span>  <\/span><\/span><span>tools<\/span><span>:<\/span><span> <\/span><span>{<\/span><span> <\/span><span>codemode<\/span><span> <\/span><span>},<\/span><\/div><\/div><div><div><span>  <\/span><span>messages<\/span><span>,<\/span><\/div><\/div><div><div><span>}<\/span><span>)<\/span><span>;<\/span><\/div><\/div><\/code><\/pre>\n<div>\n<div><\/div>\n<\/div>\n<\/figure>\n<\/div><\/div>\n<\/li>\n<li>\n<p>TypeScript<\/p>\n<div>\n<div>\n<figure>\n<pre data-language=\"ts\"><code class=\"language-ts\"><div><div><span>import <\/span><span>{<\/span><span><span> <\/span><span>createCodeTool<\/span><span> <\/span><\/span><span>}<\/span><span> from <\/span><span>\"@cloudflare\/codemode\/ai\"<\/span><span>;<\/span><\/div><\/div><div><div><span>import <\/span><span>{<\/span><span><span> <\/span><span>DynamicWorkerExecutor<\/span><span> <\/span><\/span><span>}<\/span><span> from <\/span><span>\"@cloudflare\/codemode\"<\/span><span>;<\/span><\/div><\/div><div><div><span>import <\/span><span>{<\/span><span><span> <\/span><span>streamText<\/span><span> <\/span><\/span><span>}<\/span><span> from <\/span><span>\"ai\"<\/span><span>;<\/span><\/div><\/div><div><div>\n<\/div><\/div><div><div><span>const<\/span><span> <\/span><span>executor<\/span><span> <\/span><span>=<\/span><span> <\/span><span>new<\/span><span> <\/span><span>DynamicWorkerExecutor<\/span><span>(<\/span><span>{<\/span><span> loader<\/span><span>:<\/span><span> <\/span><span>env<\/span><span>.<\/span><span>LOADER<\/span><span> <\/span><span>}<\/span><span>)<\/span><span>;<\/span><\/div><\/div><div><div><span>const<\/span><span> <\/span><span>codemode<\/span><span> <\/span><span>=<\/span><span> <\/span><span>createCodeTool<\/span><span>(<\/span><span>{<\/span><span> tools<\/span><span>:<\/span><span> <\/span><span>myTools<\/span><span>,<\/span><span> <\/span><span>executor<\/span><span> <\/span><span>}<\/span><span>)<\/span><span>;<\/span><\/div><\/div><div><div>\n<\/div><\/div><div><div><span>const<\/span><span> <\/span><span>result<\/span><span> <\/span><span>=<\/span><span> <\/span><span>streamText<\/span><span>(<\/span><span>{<\/span><\/div><\/div><div><div><span>  <\/span><span>model<\/span><span>,<\/span><\/div><\/div><div><div><span><span>  <\/span><\/span><span>tools<\/span><span>:<\/span><span> <\/span><span>{<\/span><span> <\/span><span>codemode<\/span><span> <\/span><span>},<\/span><\/div><\/div><div><div><span>  <\/span><span>messages<\/span><span>,<\/span><\/div><\/div><div><div><span>}<\/span><span>)<\/span><span>;<\/span><\/div><\/div><\/code><\/pre>\n<div>\n<div><\/div>\n<\/div>\n<\/figure>\n<\/div><\/div>\n<\/li>\n<\/ul>\n<h4>Wrangler configuration<\/h4>\n<ul>\n<li>\n<p>wrangler.jsonc<\/p>\n<div>\n<div>\n<figure>\n<pre data-language=\"jsonc\"><code class=\"language-jsonc\"><div><div><span>{<\/span><\/div><\/div><div><div><span>  <\/span><span>\"<\/span><span>worker_loaders<\/span><span>\"<\/span><span>:<\/span><span> <\/span><span>[{<\/span><span> <\/span><span>\"<\/span><span>binding<\/span><span>\"<\/span><span>:<\/span><span> <\/span><span>\"LOADER\"<\/span><span> <\/span><span>}],<\/span><\/div><\/div><div><div><span>}<\/span><\/div><\/div><\/code><\/pre>\n<div>\n<div><\/div>\n<\/div>\n<\/figure>\n<\/div><\/div>\n<\/li>\n<li>\n<p>wrangler.toml<\/p>\n<div>\n<div>\n<figure>\n<pre data-language=\"toml\"><code class=\"language-toml\"><div><div><span>[[<\/span><span>worker_loaders<\/span><span>]]<\/span><\/div><\/div><div><div><span>binding<\/span><span> <\/span><span>=<\/span><span> <\/span><span>\"LOADER\"<\/span><\/div><\/div><\/code><\/pre>\n<div>\n<div><\/div>\n<\/div>\n<\/figure>\n<\/div><\/div>\n<\/li>\n<\/ul>\n<p>See the <a href=\"https:\/\/developers.cloudflare.com\/agents\/api-reference\/codemode\/\">Code Mode documentation<\/a> for full API reference and examples.<\/p>\n<h4>Upgrade<\/h4>\n<div>\n<figure>\n<pre data-language=\"sh\"><code class=\"language-sh\"><div><div><span>npm<\/span><span> <\/span><span>i<\/span><span> <\/span><span>@cloudflare\/codemode@latest<\/span><\/div><\/div><\/code><\/pre>\n<div>\n<div><\/div>\n<\/div>\n<\/figure>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>The @cloudflare\/codemode package has been rewritten into a modular, runtime-agnostic SDK. Code Mode enables LLMs to write and execute TypeScript that orchestrates your tools, instead of calling them one at a time. This can (and does) yield significant token savings, reduces context window pressure and improves overall model performance on a task. The new Executor [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-240","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/wordpress.securinsight.ca\/index.php\/wp-json\/wp\/v2\/posts\/240","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.securinsight.ca\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wordpress.securinsight.ca\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wordpress.securinsight.ca\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wordpress.securinsight.ca\/index.php\/wp-json\/wp\/v2\/comments?post=240"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.securinsight.ca\/index.php\/wp-json\/wp\/v2\/posts\/240\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.securinsight.ca\/index.php\/wp-json\/wp\/v2\/media?parent=240"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wordpress.securinsight.ca\/index.php\/wp-json\/wp\/v2\/categories?post=240"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wordpress.securinsight.ca\/index.php\/wp-json\/wp\/v2\/tags?post=240"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}