Important
This example uses experimental parts of Cloudflare Computer: the Worker shell backend. Their APIs may change in any release, and they are not yet suitable for production use. See the status table.
A Vite-built Cloudflare Worker + Durable Object whose Workspace ships a
directory from the project, src/skills, into every workspace. It uses
computerBundle() from @cloudflare/computer/vite and WorkerBundle
from @cloudflare/computer, and works the same under vite dev,
vite preview, and a deploy.
The shell is just-bash in a Dynamic Worker, as in
examples/worker-shell, so you can read the bundled
files with ordinary commands.
// vite.config.ts
plugins: [cloudflare(), computerBundle()]// src/index.ts
import skills from "computer:bundle/src/skills";
mounts: {
"/workspace/.agents/skills": WorkerBundle(skills),
}computerBundle()resolvescomputer:bundle/src/skillsto a module that calls Vite'simport.meta.globoversrc/skills, reading each file as text, plus a version: a hash of the paths and contents, computed at build time.- Vite turns each file into its own small module. Under
vite devthey're served by Vite's module runner;vite buildemits them as chunks next toindex.js, and wrangler uploads each one as an ES module. WorkerBundle(skills)copies the files to/workspace/.agents/skillsas a read-only mount the first time the workspace is used. It loads the file modules only then.- When the version changes, the workspace replaces its copy on its next
start. In production that's a deploy that changed the files. Under
vite devit's any edit: changesrc/skills/hello/SKILL.mdand the next request sees it, without restarting the server.
There's no find_additional_modules rule in wrangler.jsonc.
@cloudflare/vite-plugin ignores it, and nothing needs to be under
/bundle.
For TypeScript, tsconfig.json adds @cloudflare/computer/vite/client
to compilerOptions.types, so the computer:bundle/… import is typed.
npm install
npm run dev --workspace @example/computer-vite-bundle# list the bundled files
curl -X POST http://localhost:5173/c/demo/exec \
-d '{"command":"ls -R /workspace/.agents/skills"}'
# read the skill
curl -X POST http://localhost:5173/c/demo/exec \
-d '{"command":"cat /workspace/.agents/skills/hello/SKILL.md"}'
# run the bundled script
curl -X POST http://localhost:5173/c/demo/exec \
-d '{"command":"sh /workspace/.agents/skills/hello/scripts/hello.sh"}'
# writes are refused: the mount is read-only
curl -X POST http://localhost:5173/c/demo/exec \
-d '{"command":"echo nope > /workspace/.agents/skills/x.txt"}'Now edit src/skills/hello/SKILL.md and run the cat again. The
workspace has the new contents.
To try the production build locally:
npm run preview --workspace @example/computer-vite-bundlevite preview serves on port 4173.
examples/vite-bundle/
vite.config.ts cloudflare() + computerBundle()
wrangler.jsonc Worker + DO + worker_loaders binding
src/index.ts Worker handler + DO (Agent)
src/skills/ Files mounted read-only at /workspace/.agents/skills
- Text files only. Files are read as UTF-8, so binary files are
corrupted. For binary files, use the wrangler form of
WorkerBundleshown inexamples/worker-shell. - Dotfiles and
node_modulesare skipped, as withimport.meta.glob. - The bundled files count toward the Worker's script size.
See Mount Interface for the full reference.