返回顶部
c

code-runner 代码运行器

Run code snippets in 30+ programming languages including JavaScript, Python, TypeScript, Java, C, C++, Go, Rust, Ruby, PHP, and more. Use when the user wants to execute code, test algorithms, verify output, run scripts, or check code behavior. Supports both interpreted and compiled languages.

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 0.1.0
安全检测
已通过
1,113
下载量
免费
免费
0
收藏
概述
安装方式
版本历史

code-runner

代码运行技能

该技能使您能够直接从命令行运行多种编程语言的代码片段。

何时使用此技能

在以下情况下使用此技能:

  • - 用户想要运行或执行代码片段
  • 测试算法实现或逻辑
  • 验证代码的预期输出
  • 运行快速脚本或单行代码
  • 检查语法或运行时行为
  • 演示代码功能

支持的语言

支持以下语言(需要安装相应的解释器/编译器):

语言命令文件扩展名
JavaScriptnode.js
TypeScript
ts-node | .ts |
| Python | python | .py |
| Java | java(编译并运行) | .java |
| C | gcc(编译并运行) | .c |
| C++ | g++(编译并运行) | .cpp |
| Go | go run | .go |
| Rust | rustc(编译并运行) | .rs |
| Ruby | ruby | .rb |
| PHP | php | .php |
| Perl | perl | .pl |
| Lua | lua | .lua |
| R | Rscript | .r |
| Swift | swift | .swift |
| Kotlin | kotlin | .kts |
| Scala | scala | .scala |
| Groovy | groovy | .groovy |
| Dart | dart | .dart |
| Julia | julia | .jl |
| Haskell | runhaskell | .hs |
| Clojure | clojure | .clj |
| F# | dotnet fsi | .fsx |
| C# | dotnet script | .csx |
| PowerShell | pwsh | .ps1 |
| Bash | bash | .sh |
| Batch | cmd /c | .bat |
| CoffeeScript | coffee | .coffee |
| Crystal | crystal | .cr |
| Elixir | elixir | .exs |
| Nim | nim compile --run | .nim |
| OCaml | ocaml | .ml |
| Racket | racket | .rkt |
| Scheme | scheme | .scm |
| Lisp | sbcl --script | .lisp |

详细语言配置请参见 references/LANGUAGES.md

如何运行代码

步骤1:识别语言

通过以下方式确定编程语言:

  • - 用户的明确请求(例如运行这段Python代码)
  • 提供的文件扩展名
  • 代码语法模式

步骤2:使用运行脚本执行

⚠️ 对AI代理重要提示:使用标准输入以避免引号、反斜杠和特殊字符的转义问题。

推荐方法(标准输入):
bash
echo <代码> | node scripts/run-code.cjs <语言ID>

替代方法(CLI参数 - 仅适用于简单代码):
bash
node scripts/run-code.cjs <语言ID> <代码>

示例 - JavaScript:
bash
echo console.log(Hello, World!) | node scripts/run-code.cjs javascript

示例 - Python:
bash
echo print(Hello, World!) | node scripts/run-code.cjs python

示例 - Java(多行):
bash
echo public class Test {
public static void main(String[] args) {
System.out.println(\Hello from Java!\);
}
} | node scripts/run-code.cjs java

示例 - 从变量传入多行代码:
bash

在bash中


CODE=import math
print(Pi:, math.pi)
print(Result:, math.factorial(5))
echo $CODE | node scripts/run-code.cjs python

在PowerShell中(内联here-string)

@ import math print(Pi:, math.pi) print(Result:, math.factorial(5)) @ | node scripts/run-code.cjs python

步骤3:返回结果

  • - 向用户显示输出(标准输出)
  • 如果有错误(标准错误),解释出错原因
  • 针对常见错误建议修复方法

平台说明

Windows

  • - 批处理脚本使用 cmd /c
  • PowerShell脚本需要 pwsh 或 powershell
  • 路径分隔符使用反斜杠 \

macOS / Linux

  • - Bash脚本原生支持
  • Swift在macOS上可用
  • 可移植脚本使用 #!/usr/bin/env shebang

错误处理

常见问题及解决方案:

  1. 1. 命令未找到:语言解释器未安装或不在PATH中
- 建议安装所需的运行时 - 提供安装说明
  1. 2. 语法错误:代码存在语法问题
- 显示错误信息 - 如果可用,指向行号
  1. 3. 运行时错误:代码运行但执行失败
- 显示堆栈跟踪 - 解释错误类型
  1. 4. 超时:代码执行时间过长(默认:30秒)
- 警告可能存在无限循环 - 建议优化

安全考虑

⚠️ 重要提示:运行任意代码可能存在危险。始终:

  1. 1. 在执行前审查代码
  2. 对以下类型的代码保持警惕:
- 访问文件系统 - 发起网络请求 - 执行系统命令 - 修改环境变量
  1. 3. 对于不可信代码,考虑在沙盒环境中运行

示例

示例1:运行JavaScript计算

bash echo console.log(Array.from({length: 10}, (_, i) => i * i)) | node scripts/run-code.cjs javascript

输出:[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]

示例2:运行带导入的Python代码

bash echo import math; print(math.factorial(10)) | node scripts/run-code.cjs python

输出:3628800

示例3:测试Go函数

bash echo package main; import fmt; func main() { fmt.Println(Hello from Go!) } | node scripts/run-code.cjs go

输出:Hello from Go!

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 code-runner-1776072309 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 code-runner-1776072309 技能

通过命令行安装

skillhub install code-runner-1776072309

下载

⬇ 下载 code-runner v0.1.0(免费)

文件大小: 8.4 KB | 发布时间: 2026-4-15 12:13

v0.1.0 最新 2026-4-15 12:13
- Initial release of the code-runner skill.
- Run code snippets in 30+ programming languages including JavaScript, Python, Java, C, Go, Rust, Ruby, PHP, and more.
- Supports both interpreted and compiled languages.
- Securely execute code via stdin to avoid escaping issues.
- Provides error handling, language detection tips, and platform-specific notes.
- Includes usage examples and security guidance.

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部