exec

GitHub

说明 exec 技能用于执行 ECMAScript 模块而非 Shell 命令。需在动态 Worker 中评估代码,支持 Node.js 内置模块及文件系统操作,限制网络访问与资源大小,适用于自动化脚本处理。

examples/worker-javascript/src/skills/exec/SKILL.md cloudflare/computer

触发场景

需要运行 JavaScript 代码片段 使用 node:fs/promises 进行文件读写操作 执行失败提示 Disallowed operation

安装

npx skills add cloudflare/computer --skill exec -g -y
更多选项

非标准路径

npx skills add https://github.com/cloudflare/computer/tree/main/examples/worker-javascript/src/skills/exec -g -y

不安装直接使用

npx skills use cloudflare/computer@exec

指定 Agent (Claude Code)

npx skills add cloudflare/computer --skill exec -a claude-code -g -y

安装 repo 全部 skill

npx skills add cloudflare/computer --all -g -y

预览 repo 内 skill

npx skills add cloudflare/computer --list

SKILL.md

Frontmatter
{
    "name": "exec",
    "description": "How exec works in this workspace. The command is the source of an ECMAScript module, evaluated in a fresh Dynamic Worker, not a shell command. Read this before running code, and when a run fails with \"Disallowed operation called within global scope\" or returns nothing."
}

Running code

Every exec call takes JavaScript module source, not a shell command. The durable object builds a module graph from it, starts a fresh Dynamic Worker, and evaluates the module there. Nothing is shared between calls.

The shape of a module

Put the work inside the default export, and return what you want back:

import { readdir, readFile } from "node:fs/promises";

export default async function (input) {
  const names = await readdir(input.dir);
  const first = await readFile(`${input.dir}/${names[0]}`, "utf8");
  return { count: names.length, first };
}
  • The default export gets the call's input value.
  • Its return value comes back as the result's value. It must be JSON-compatible.
  • console.log and console.info go to standard output. console.warn and console.error go to standard error.
  • A thrown error ends the run with a non-zero exit code and the message on standard error. So does a promise that rejects with nothing handling it, so await everything you start.
  • Code at the top level runs before the call is set up. A file read or a fetch there fails with Disallowed operation called within global scope. Imports at the top are fine.

What code can import

  • node:fs/promises (also node:fs): the workspace's files. The supported calls are readFile, writeFile, mkdir, rm, readdir, stat, lstat, readlink, symlink, chmod and access. All of them are async.
  • Node.js built-ins such as node:path, node:crypto, node:zlib and node:buffer, with subpaths like node:stream/promises. Bare names such as path work too.
  • Relative imports resolve from cwd in the workspace, so you can write a helper module with one call and import it in the next.
  • There is no node_modules lookup and no npm. Beyond the modules above, only the ones the host configures are available.

Limits

  • No direct network access. fetch to the internet fails.
  • Each run has a time limit: one minute by default, three at most.
  • Source, input and the returned value are capped at 1 MiB each.

Files

  • cwd defaults to /workspace.
  • File operations go straight to the durable object's storage. There's nothing to sync, so a write is visible to the next call right away.
  • /workspace/r2 is a read-only copy of an R2 bucket.
  • /workspace/.agents/skills (where this file lives) is a read-only copy of files shipped with the Worker. Writing under either one fails with EROFS.

版本历史

  • 7415a44 当前 2026-10-18 18:09

同 Skill 集合

.agents/skills/capnweb/SKILL.md
.agents/skills/cloudflare/SKILL.md
.agents/skills/debugging-computerd-fuse/SKILL.md
.agents/skills/prose/SKILL.md
.agents/skills/pull-requests/SKILL.md
.agents/skills/test-driven-development/SKILL.md
.gardener/SKILL.md
examples/container/src/skills/exec/SKILL.md
examples/vite-bundle/src/skills/hello/SKILL.md
examples/worker-shell/src/skills/exec/SKILL.md

元信息

文件数
0
版本
7415a44
Hash
568f8bf2
收录时间
2026-10-18 18:09

首页 - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-10-19 05:13
浙ICP备14020137号-1