How Cloudflare Computer runs code for AI agents
By Flavio
Tagged: Cloudflare
How Cloudflare Computer combines a Durable Object filesystem, Dynamic Worker runtimes, a container backend, FUSE mount, and sync protocol.
Cloudflare just introduced @cloudflare/computer. When I saw the name, I immediately pictured a virtual machine, but it works differently. Instead of keeping one machine running forever, it puts a durable filesystem inside a Durable Object and wires it up to a few different places where an AI agent can run code. (If you want a persistent Linux VM over SSH with an HTTPS URL, check out exe.dev instead.)
Small jobs can run in a fast isolate, JavaScript modules can run in a fresh Dynamic Worker, and commands that need Linux can run in a container. All three share the same files. Cloudflare is trying to keep the container optional for most of an agent’s work, so you don’t spin one up for every single task.
One heads-up before you dig in: this is an MIT-licensed early preview meant for experiments and prototypes, not production. The repo is moving fast, so expect the APIs and internals to change.
If you’re new to Cloudflare’s platform, start with my complete Cloudflare guide (also available as the free Cloudflare Handbook), which covers Workers, storage, Durable Objects, Queues, Workflows, and the rest of the building blocks behind this project.
The architecture in one picture
Here’s how all the pieces fit together:
Each agent gets a Durable Object for stable identity and private storage, with the SQLite database inside acting as the source of truth for the filesystem. From there, a runtime router decides where each task should run. The two Worker backends talk directly to that Durable Object filesystem, while the container keeps a second copy behind a FUSE mount and syncs changes before and after every command.
Right now, the package ships with three execution backends:
- a Worker shell built with
just-bash - a Worker JavaScript runtime
- a full Linux container
Cloudflare’s announcement focuses on the Worker shell and the container, though the repo already includes that third backend for running ECMAScript modules in a fresh Dynamic Worker. Because the codebase is ahead of the preview announcement, expect the APIs to keep shifting.
The computer starts with a filesystem
You don’t even have to configure an execution backend to get started. Creating a Workspace on its own gives your agent a durable working directory:
const workspace = new Workspace({
storage: this.ctx.storage,
})
await workspace.fs.mkdir('/workspace', { recursive: true })
await workspace.fs.writeFile('/workspace/notes.md', '# Notes\n')
The API feels like node:fs/promises, with methods like readFile(), writeFile(), mkdir(), readdir(), rm(), and grep(). Under the hood, these calls update SQLite tables inside the Durable Object instead of touching a normal disk.
How a filesystem fits inside SQLite
The filesystem itself lives in a private package called @cloudflare/dofs. Its SQLite schema splits the storage into a handful of focused tables:
vfs_nodesstores files, directories, and symbolic linksvfs_direntsmaps a directory name to a child inodevfs_chunksmaps file positions to content chunksvfs_blobstracks content by hashvfs_blob_bytesholds the raw bytes- sync tables track deletions, cursors, mounts, and watermarks
Rather than stuffing an entire file into a single SQLite value, it slices files into fixed 512 KiB chunks and hashes each chunk with SHA-256. Each file then points to an ordered list of those hashes:
/workspace/report.pdf
chunk 0 → 9f2a...
chunk 1 → 27bc...
chunk 2 → c841...
If you’ve worked with Git or content-addressed storage before, this will look familiar. Names point to content while hashes identify the bytes, so identical chunks only get stored and sent over the wire once. Editing part of a large file doesn’t force you to re-transfer the whole thing. Every write also increments a monotonic revision number, which lets the Workspace ask any backend for everything that changed since its last cursor.
A Durable Object is the owner
Picking Durable Objects for this makes a lot of sense. An agent needs more than a place to dump files; it needs a single coordinator that owns its state and manages execution, and a Durable Object handles both jobs.
You can map one object to an agent, a user, a project, or a session, and every request for that ID routes to the same logical instance. When the object goes idle and leaves memory, the SQLite workspace sticks around and comes right back when it starts again. You get roughly 10 GB of storage per workspace, shared with whatever else that Durable Object stores, so treat it as an agent working directory rather than a huge development disk.
One execution API, several backends
No matter which runtime you target, you kick off work through the same method:
const run = await workspace.runtime.exec('npm test', {
backend: 'container',
encoding: 'utf8',
})
const result = await run.result()
The execution handle you get back is also a ReadableStream, so you can stream standard output and standard error while the command runs. You can reconnect to supported executions by ID, stop them early, or dispose of their stored records when you’re done.
Backends connect lazily, so creating a Workspace won’t boot every runtime up front. The first backend you configure becomes the default, and you can pick any other backend by passing its ID. Just watch out for one detail behind that shared API: source means different things depending on where it runs. For the shell and container backends, it’s a shell command, while for the JavaScript backend, it’s an ECMAScript module.
The Worker shell runs without Linux
For lightweight commands, the Worker shell runs just-bash inside a Dynamic Worker. Dynamic Workers use the same isolate model as regular Cloudflare Workers, powered by the open-source runtime I covered in my workerd deep dive.
Because just-bash interprets shell commands in JavaScript, you get common text and filesystem utilities without starting a Linux machine. The Dynamic Worker opens a narrow RPC connection back to the Workspace, so a command like this reads straight from the authoritative SQLite filesystem:
grep -R "TODO" /workspace
There’s no second copy of the files and no sync step to wait for. You can also opt into extra command groups like curl, jq, python, sqlite, yq, and xan, leaving unused ones out of the bundle.
This works great for inspecting files, processing text, running Git operations, and other jobs that don’t need a real operating system. Keep in mind it isn’t a Linux emulator, though, so anything that needs native binaries, package installation, a compiler, or a full process environment still belongs in the container.
The JavaScript backend runs a module
The Worker JavaScript backend works differently. Every time you run code on it, Cloudflare Computer spins up a fresh Dynamic Worker, builds a module graph, validates the imports, passes in structured input, and collects a structured result.
Inside that module, you can use an async subset of node:fs/promises:
import fs from 'node:fs/promises'
export default async function () {
const input = await fs.readFile('/workspace/input.txt', 'utf8')
await fs.writeFile('/workspace/output.txt', input.toUpperCase())
return { bytes: input.length }
}
Those filesystem calls cross a capability bridge back to the Durable Object. The Dynamic Worker never receives the Durable Object’s storage binding, loader binding, credentials, or the complete Workspace object, only the capabilities the host explicitly installs.
By default, network access is off and environment variables only include values supplied for that execution. You can also configure limits on source size, input, output, standard streams, CPU time, wall-clock time, and capability traffic. For trusted host operations, the runtime reserves ws: modules, currently shipping ws:git and ws:artifacts. That keeps the code sandboxed in the isolate while the host stays in control of its capabilities.
The container is the heavy backend
When a task needs a real Linux environment, Cloudflare Computer starts a Cloudflare Container running a daemon named computerd. Because computerd ships as a self-contained Node single executable application, your container image doesn’t need its own Node.js installation.
The daemon handles four main jobs:
- mounting the workspace at
/workspacethrough FUSE - recording file changes made inside the container
- running shell commands
- syncing changes with the Durable Object
FUSE lets a userspace program implement a filesystem. As far as a compiler or package manager inside the container can tell, /workspace/app.ts is just a regular file on disk, while computerd reads and writes the SQLite-backed virtual filesystem behind the scenes.
You can put whatever the task requires into that container: Node.js, Python, pandoc, FFmpeg, compilers, or native libraries. Compared to the more traditional approach I showed in my Vercel Sandbox tutorial, where untrusted code gets an isolated Linux microVM from the start, Cloudflare Computer only pays for a full Linux environment when a command actually needs it.
The container has a second copy of the filesystem
Unlike the Worker backends, the container can’t call back to the Durable Object for every kernel filesystem operation. Instead, it keeps its own local virtual filesystem behind the FUSE mount, and Cloudflare Computer syncs the two sides around every command. Before a container command starts, it pushes Durable Object changes into the container; after the command finishes, it pulls container changes back.
Here’s what that full round trip looks like:
Durable Object SQLite
↓ push changed paths and missing chunks
container VFS behind /workspace
↓ run command
container records new revisions
↓ pull changed paths and missing chunks
Durable Object SQLite
The sync protocol sends metadata first, listing chunk hashes instead of inline bytes. The receiver checks which hashes it already has, so the sender only transfers the missing chunks. Repeated writes to the same path also get coalesced: if the host overwrites a file five times between container runs, the container only receives the latest version once.
Pulls run in batches of 256 entries, and the Durable Object saves a cursor after every committed batch so a crash mid-sync doesn’t restart a large pull from the beginning. Deletes travel as tombstones, and renames don’t have a special wire operation; the protocol sends the final state as new paths paired with tombstones for the old ones. That costs more for a large directory move, but it keeps replay and recovery idempotent.
What happens when both sides change a path?
Conflict resolution uses last-writer-wins behavior. If an incoming change has a different node type than what’s already at that path, the receiver deletes the local tree there and applies the incoming entry.
That’s practical for an agent workspace, though you shouldn’t treat it like collaborative editing or a distributed transaction. Most of the time, the normal command lifecycle avoids conflicts on its own:
- push host changes
- run one command
- pull container changes
If your app writes to the same paths concurrently from both sides, you’ll need to handle that boundary yourself.
How the Durable Object reaches the container
computerd exposes a Cap’n Web RPC interface over WebSockets, though the connection flows in the opposite direction from what you’d expect. Rather than having the Durable Object open a normal inbound connection to the container, it asks computerd to open an outbound WebSocket. Cloudflare intercepts that container request and routes it back to the owning Durable Object:
Durable Object → POST /connect → container
Durable Object ← intercepted WebSocket ← computerd
That inverted connection gives both sides one bidirectional RPC session for syncing files and running commands. One caveat right now: if the WebSocket drops, the backend won’t transparently splice in a replacement, so the calling code has to reconstruct the Workspace.
The agent tools are smaller than the computer
Cloudflare Computer also includes tools for the Vercel AI SDK. Out of the box, the default writable set gives your agent four file tools:
readwriteeditls
You can also add exec and file publishing. The four file tools work on the Workspace directly, so your agent can inspect and edit files without starting a container.
When you enable exec, you pass backend names and descriptions so the model can pick the right one for the job:
const tools = createAITools({
workspace,
shell: {
defaultBackend: 'worker',
backends: {
worker: {
description: 'Fast text and file commands',
},
container: {
description: 'Full Linux with native binaries',
},
},
},
})
Just remember that letting the model choose a backend from a description isn’t an authorization check. If you put this behind a public gateway, validate which backends a given capability is allowed to select instead of trusting whatever backend name the model sends back.
Git does not need a shell
The Workspace also includes an optional Git client built with isomorphic-git that works directly against the SQLite filesystem. An agent can clone a repo, check status, stage files, create commits, and manage branches without starting a container.
Networked Git operations sit behind a separate capability. The JavaScript backend denies them by default, so local Git stays available even when network access isn’t enabled.
How I would use Cloudflare Computer
I build a lot of small products that coding agents can maintain and extend. Most of that work is straightforward: the agent reads the repo, searches for the right files, edits some code, runs a few checks, and hands back the result. That’s the exact kind of loop Cloudflare Computer is built for.
The cleanest setup is one Workspace per project or task. You let the Git client clone the repository straight into the Durable Object filesystem, then let the Worker shell handle searches, diffs, JSON, Markdown, and small file edits while project-specific scripts run in the JavaScript backend. You only spin up a container at the end for the full build or test suite.
Take Events Logger, which is an Astro app with Drizzle and SQLite. Updating a dashboard, adding a new event type, tweaking a report, or generating docs can all stay inside the Worker runtimes. Only dependency installs, database migrations, and the full Astro test and build process need the container. There’s a clear boundary on data, too: Events Logger keeps its production data in a local SQLite database, and Cloudflare Computer doesn’t get access to it on its own. That database stays separate unless you expose a narrow API or upload an export on purpose.
Broadcast Keep runs into a different limit because it works with yt-dlp, FFmpeg, and large video files. A container is the right place for those native tools, but copying multi-gigabyte recordings into the Workspace filesystem doesn’t make sense. The media belongs in object storage or on a regular disk, while the Workspace holds the source code, recording manifests, logs, metadata, and repair instructions.
Port Pilot and Local Hoster hit the local-machine boundary. Both exist to inspect and control my Mac, and a remote Cloudflare Computer can’t replace that local access. An agent can still work on their source code in a Workspace, but it won’t see local processes, ports, certificates, or Keychain unless you build a bridge and explicitly grant access.
In practice, Cloudflare Computer fits best as a durable workspace for an agent’s code and metadata, leaving local machines and bulk media storage where they belong.
The performance tradeoff
This filesystem is tuned for agent workspaces rather than raw disk throughput. In Cloudflare’s benchmark comparing the computerd FUSE mount against memory and the container’s ext4 disk, metadata-heavy tasks come out ahead: directory traversal, git init, and a small Git clone all beat the ext4 baseline.
Large sequential files are a different story. Reading or copying a 64 MiB file through the mount ran roughly 30 to 40 times slower than the disk baseline. Installing the 854-package cloudflare/sandbox-sdk dependency tree took 124.7 seconds through computerd, compared with 63.9 seconds on ext4.
The bottleneck is the same thing that makes syncing fast: every 512 KiB chunk gets hashed and stored by content. That tradeoff works great for source files, Git operations, generated docs, and incremental edits, while falling behind on large media files or massive dependency trees. That’s why Cloudflare recommends sticking to small, agent-scale workspaces instead of stuffing a full monorepo in there.
What survives a restart?
The Durable Object filesystem is the source of truth and survives restarts, while the container’s local filesystem lives in memory. If the container process restarts, that local copy disappears, and the next push from the Durable Object rebuilds the container state.
Because the durable identity lives in the Workspace rather than in any single Linux process, the container stays disposable and losing it doesn’t mean losing your files.
Why this design matters
The usual way to give an agent a computer is to spin up a container and leave it running. You get a familiar shell, filesystem, processes, packages, and networking, but you’re also making the most expensive runtime the default for every single action.
Cloudflare Computer flips that starting point. The filesystem and agent state live in a horizontally scalable Durable Object, fast isolate runtimes handle routine file and code work, and a container becomes just another tool the agent calls when it really needs Linux. It’s the same rule I use in my Production at the Edge mini-course: start with the smallest architecture that works, and only add heavier infrastructure when a real requirement asks for it.
Cloudflare wants containers to be necessary for less than 10% of an agent’s work. The preview shows the exact split they’re testing to get there: the agent works with files and tools, while the platform picks a Worker or a container for each step.
Want me to talk about your product? You can sponsor this site.
Related posts about cloudflare: