GetNotes Tools
cloudflare/computer
Tool นี้คืออะไร
Cloudflare Computer เป็นระบบไฟล์เสมือนที่ทำงานภายใน Durable Object ของ Cloudflare ซึ่งเก็บสถานะใน SQLite และมีสภาพแวดล้อมการรันโค้ดที่หลากหลาย (เช่น คอนเทนเนอร์, เชลล์, JavaScript) เหมาะสำหรับนักพัฒนาที่ต้องการสร้างแอปพลิเคชันทดลองหรือต้นแบบที่ต้องการระบบไฟล์ถาวรและพื้นที่รันโค้ดบน Cloudflare Workers.
ข้อมูลโปรเจกต์
ดาว
6.7K
Forks
342
License
MIT
อัปเดต GitHub ล่าสุด
7 ส.ค. 2569
เพิ่มใน GetNotes
17 ส.ค. 2569
Repository
cloudflare/computer
แปลและเรียบเรียงโดย AI
เนื้อหาฉบับภาษาไทย
ใช้อ่านเพื่อทำความเข้าใจเบื้องต้น โปรดตรวจสอบรายละเอียดสำคัญกับเอกสารต้นฉบับด้านล่าง
Cloudflare Computer
Cloudflare Computer คือระบบไฟล์เสมือนที่ทำงานอยู่ภายใน Durable Object โดย Durable Object จะเก็บสถานะที่เป็นแหล่งข้อมูลหลักใน SQLite และเปิดเผยพื้นผิวการประมวลผลที่สามารถเสียบปลั๊กได้ผ่าน workspace.runtime ซึ่งปัจจุบันมีแบ็กเอนด์ให้ใช้งานสามแบบ:
- Container จะฉายสถานะ SQLite เข้าไปในคอนเทนเนอร์แซนด์บ็อกซ์ในรูปแบบ FUSE mount จริง แดมอนฝั่งแซนด์บ็อกซ์ (
computerd) จะเมาต์สถานะเป็นระบบไฟล์และซิงค์การเปลี่ยนแปลงกลับผ่านช่องทาง RPC ของ capnweb โดยมี Linux userland เต็มรูปแบบ, ไบนารีจริง และเครือข่ายจริง - Isolate shell รัน just-bash ใน Dynamic Worker โดยจะเข้าถึง Workspace ที่เป็นแหล่งข้อมูลหลักผ่าน Workers RPC จึงไม่มีการจัดเก็บข้อมูลสำรองหรือการซิงค์ไปกลับ
- Isolate JavaScript รันโมดูล ECMAScript ใน Dynamic Worker ใหม่ พร้อมอินพุต/ผลลัพธ์ที่มีโครงสร้าง, การนำเข้าแบบสัมพันธ์ที่คงทน, ไลบรารีที่กำหนดค่าไว้,
node:fs/promisesที่รองรับโดย Workspace และโมดูลws:gitและws:artifactsที่เชื่อถือได้
Workspace สามารถลงทะเบียนแบ็กเอนด์ได้หลายตัวภายใต้ ID ที่เสถียร workspace.runtime.exec(source, { backend }) เป็นจุดเข้าใช้งานการประมวลผลเพียงจุดเดียว โดยแบ็กเอนด์ที่เลือกจะกำหนดว่า source เป็นคำสั่งเชลล์หรือโมดูล ECMAScript แบ็กเอนด์จะเชื่อมต่อแบบ lazy เมื่อมีการใช้งานครั้งแรก
Workspace ยังสามารถสร้างขึ้นโดยไม่มีแบ็กเอนด์เลยก็ได้ ซึ่งจะทำให้ผู้เรียกใช้งานสามารถเข้าถึงระบบไฟล์ได้ด้วยตัวเอง
สำหรับพรีวิวเท่านั้น แพ็กเกจนี้จัดทำขึ้นเพื่อการแสดงตัวอย่างสำหรับรับข้อเสนอแนะเท่านั้น API ยังไม่เสถียรและการออกแบบอาจมีการเปลี่ยนแปลง
เหมาะสำหรับการทดลอง, การสำรวจ และการสร้างต้นแบบ ยังไม่เหมาะสำหรับการใช้งานจริงในขณะนี้
ข้อมูลจำเพาะภายใต้ docs/ เป็นการมองไปข้างหน้า — โปรดอ่านเพื่อทำความเข้าใจเจตนา ไม่ใช่เพื่ออธิบายโค้ดในปัจจุบัน
การใช้งาน
หากคุณต้องการสร้างบน Cloudflare Computer ให้ติดตั้ง @cloudflare/computer และปฏิบัติตาม README ของแพ็กเกจนั้น — ซึ่งมีขั้นตอนการติดตั้ง, แผนผังจุดเข้าใช้งาน และตัวอย่างการใช้งาน fs และ runtime
หากต้องการส่งข้อเสนอแนะ โปรดดูที่ CONTRIBUTING.md
ผู้ร่วมงานที่ได้รับการอนุมัติควรปฏิบัติตาม COLLABORATORS.md สำหรับคำแนะนำในการตั้งค่า, การสร้าง และการทดสอบ
ตัวอย่าง
ไดเรกทอรี examples/ มีตัวอย่างผู้ใช้งานที่สามารถรันได้ของพื้นผิวสาธารณะ แต่ละตัวอย่างเป็น Worker workspace ที่มี README ของตัวเอง
examples/container— รันcomputerdภายในคอนเทนเนอร์, เมาต์ workspace และสื่อสารกับ Durable Object ผ่าน capnweb เป็นพื้นผิว HTTP สำหรับwrite/read/execexamples/worker-shell— พื้นผิว HTTP เดียวกันกับตัวอย่างคอนเทนเนอร์ แต่เชลล์รัน just-bash ใน Dynamic Worker ที่โหลดผ่านenv.LOADERไม่มีคอนเทนเนอร์examples/worker-javascript— สะท้อนworker-shellแต่execจะประเมินโมดูล ECMAScript ใน Dynamic Worker แทนที่จะรันคำสั่งเชลล์examples/egress— ส่ง URL หนึ่งรายการผ่านแบ็กเอนด์คอนเทนเนอร์, Worker shell และ Worker JavaScript ด้วยนโยบาย egress ที่ตรงกันคือnone,allหรือแบบกำหนดเองexamples/mcp— ตัวอย่าง Computer MCP: เครื่องมือ Code Modecodeหนึ่งตัวที่รองรับโดย durable workspace, Worker shell และคอนเทนเนอร์ Linux เต็มรูปแบบexamples/think— เอเจนต์แชท@cloudflare/thinkที่ใช้ workspace เป็นไดเรกทอรีการทำงาน สามารถเข้าถึงได้จากเทอร์มินัลexamples/think-compare-runtimes— UI บนเว็บที่รันงานเอเจนต์เดียวกันกับรันไทม์คอนเทนเนอร์และ Worker แบบเคียงข้างกันexamples/tutorial— การสร้างทีละขั้นตอน: หนึ่งเอนด์พอยต์, หนึ่งเอเจนต์ที่เขียนการ์ดสูตรอาหาร markdown บนโฮสต์และรันpandocบนการ์ดนั้นในคอนเทนเนอร์เพื่อสร้าง PDFexamples/artifacts— สร้างโปรเจกต์ Worker ใน workspace และเผยแพร่ไปยัง Cloudflare Artifacts เป็น repo ที่พร้อมสำหรับการโคลนexamples/assets— เปลี่ยนข้อความแจ้งเป็นรูปภาพด้วย Workers AI, เขียนลงใน workspace และส่งคืนลิงก์ที่แชร์ได้ผ่าน@cloudflare/computer/assets
โครงสร้าง Repository
repo นี้เป็น monorepo ขนาดเล็ก แต่ละแพ็กเกจมี README ของตัวเองพร้อมสถานะและบันทึกการใช้งานเฉพาะแพ็กเกจ
packages/dofs(@cloudflare/dofs) — ระบบไฟล์เสมือนที่รองรับโดย Durable Object SQLite, บล็อกการสร้างโปรโตคอลการซิงค์ และผู้ให้บริการ@platformatic/vfsสำหรับ Nodepackages/rpc(@cloudflare/computer-rpc) — ชนิดข้อมูล wire ของ capnweb และตัวช่วยเซิร์ฟเวอร์/ไคลเอนต์ที่ใช้ร่วมกันระหว่าง Durable Object และcomputerdpackages/computerd(@cloudflare/computerd) — แดมอนcomputerd: FUSE mount บวกกับเซิร์ฟเวอร์ HTTP/WebSocket RPC ที่รันอยู่ภายในคอนเทนเนอร์แซนด์บ็อกซ์packages/computer(@cloudflare/computer) — แพ็กเกจ Computer ระดับบนสุดที่ Durable Objects ใช้งาน อยู่ระหว่างการพัฒนาpackages/computer-computerd-linux-x64— บริบทอิมเมจ Docker ส่วนตัวสำหรับไบนารีcomputerdlinux-x64 ที่สร้างไว้ล่วงหน้า อิมเมจนี้ไม่ใช่แพ็กเกจ npm แต่เป็นอาร์ติแฟกต์การเผยแพร่
ประสิทธิภาพ
FUSE mount ของ computerd ทำงานได้ดีกว่าดิสก์จริงในงานที่เน้นเมตาดาต้า และตามหลังในงาน I/O แบบลำดับขนาดใหญ่ โปรดดู docs/19_performance.md สำหรับตัวเลข fs-bench เต็มรูปแบบ, การเปรียบเทียบ npm install ของ cloudflare/sandbox-sdk และวิธีการทำซ้ำ
เอกสารประกอบ
docs/— ข้อมูลจำเพาะการออกแบบ เป็นการมองไปข้างหน้า; ถือเป็นเจตนาdocs/19_performance.md— เกณฑ์มาตรฐานระบบไฟล์
การมีส่วนร่วม
เรายอมรับรายงานข้อผิดพลาด, ข้อเสนอการแก้ไข, คำขอคุณสมบัติ และข้อเสนอการออกแบบผ่าน issues และ discussions เราไม่ยอมรับ pull requests ที่ไม่ได้ร้องขอ โปรดดู CONTRIBUTING.md สำหรับช่องทางการมีส่วนร่วมสาธารณะ
ผู้ร่วมงานที่ได้รับการอนุมัติควรปฏิบัติตาม COLLABORATORS.md สำหรับการตั้งค่า, การจัดรูปแบบ, การทดสอบ, ข้อความคอมมิต และข้อตกลง pull request
หากคุณกำลังทำงานใน repo นี้ในฐานะเอเจนต์ ให้เริ่มต้นด้วย AGENTS.md และทักษะภายใต้ .agents/skills/
ใบอนุญาต
MIT โปรดดู LICENSE
เอกสารโปรเจกต์
อ่านเอกสารต้นฉบับ
README วิธีติดตั้ง วิธีใช้งาน และข้อกำหนดจาก repository ต้นฉบับ
Cloudflare Computer
Cloudflare Computer is a virtual filesystem that lives inside a
Durable Object. The Durable Object holds the authoritative state in
SQLite and exposes one pluggable execution surface through
workspace.runtime. Three backends ship today:
- Container projects the SQLite state into a sandbox container as
a real FUSE mount. A sandbox-side daemon (
computerd) mounts the state as a filesystem and syncs changes back over a capnweb RPC channel. Full Linux userland, real binaries, real network. - Isolate shell runs just-bash in a Dynamic Worker. It reaches the authoritative Workspace over Workers RPC, so there is no second store or sync round trip.
- Isolate JavaScript runs an ECMAScript module in a fresh Dynamic
Worker with structured input/results, durable relative imports,
configured libraries, Workspace-backed
node:fs/promises, and trustedws:gitandws:artifactsmodules.
A Workspace may register multiple backends under stable IDs.
workspace.runtime.exec(source, { backend }) is the single execution
entry point; the selected backend defines whether source is a shell
command or an ECMAScript module. Backends connect lazily on first use.
Workspace can also be constructed without a backend at all, giving callers the filesystem on its own.
PREVIEW ONLY This package is provided as a preview for feedback only. APIs are unstable and the design is subject to change.
Suitable for experiments, exploration and prototypes. It is NOT suitable for production use at this time.
The specification under docs/ is forward-looking — read it for
intent, not as description of the code today.
Using it
If you want to build on Cloudflare Computer, install
@cloudflare/computer and follow that
package's README — it has the installation steps, the entrypoint map,
and worked examples of the fs and runtime surfaces.
To contribute feedback, see CONTRIBUTING.md.
Approved collaborators should follow COLLABORATORS.md
for setup, build, and test instructions.
Examples
The examples/ directory holds runnable consumers of the
public surface. Each is a Worker workspace with its own README.
examples/container— runscomputerdinside a container, mounts a workspace, and talks to a Durable Object over capnweb. Awrite/read/execHTTP surface.examples/worker-shell— same HTTP surface as the container example, but the shell runs just-bash in a Dynamic Worker loaded throughenv.LOADER. No container.examples/worker-javascript— mirrorsworker-shell, butexecevaluates an ECMAScript module in a Dynamic Worker instead of running a shell command.examples/egress— sends one URL through the container, Worker shell, and Worker JavaScript backends with matchingnone,all, or custom egress policies.examples/mcp— a Computer MCP example: one Code Modecodetool backed by a durable workspace, a Worker shell, and a full Linux container.examples/think— a@cloudflare/thinkchat agent that uses the workspace as its working directory, reachable from a terminal.examples/think-compare-runtimes— a web UI that runs the same agent task against the container and worker runtimes side by side.examples/tutorial— a step-by-step build: one endpoint, one agent that writes a markdown recipe card on the host and runspandocon it in the container to produce a PDF.examples/artifacts— generates a Worker project in a workspace and publishes it to Cloudflare Artifacts as a clone-ready repo.examples/assets— turns a prompt into an image with Workers AI, writes it to the workspace, and returns a shareable link through@cloudflare/computer/assets.
Repository layout
The repo is a small monorepo. Each package has its own README with package-specific status and usage notes.
packages/dofs(@cloudflare/dofs) — Durable Object SQLite-backed virtual filesystem, sync protocol building blocks, and a@platformatic/vfsprovider for Node.packages/rpc(@cloudflare/computer-rpc) — capnweb wire types and server/client helpers shared between the Durable Object andcomputerd.packages/computerd(@cloudflare/computerd) — thecomputerddaemon: a FUSE mount plus HTTP/WebSocket RPC server that runs inside the sandbox container.packages/computer(@cloudflare/computer) — the top-level Computer package consumed by Durable Objects. Work in progress.packages/computer-computerd-linux-x64— private Docker image context for the prebuiltcomputerdlinux-x64 binary. The image, not an npm package, is the release artifact.
Performance
computerd's FUSE mount beats real disk on metadata-heavy work and
trails it on large sequential I/O. See
docs/19_performance.md for the full fs-bench
numbers, a cloudflare/sandbox-sdk npm install comparison, and how
to reproduce them.
Documentation
docs/— design specification. Forward-looking; treat as intent.docs/19_performance.md— filesystem benchmarks.
Contributing
We accept bug reports, fix proposals, feature requests, and design
proposals through issues and discussions. We do not accept unsolicited
pull requests. See CONTRIBUTING.md for the public
contribution paths.
Approved collaborators should follow
COLLABORATORS.md for setup, formatting, testing,
commit message, and pull request conventions.
If you're working in this repo as an agent, start with
AGENTS.md and the skills under
.agents/skills/.
License
MIT. See LICENSE.
