$npx -y skills add formulahendry/agent-skill-code-runner --skill code-runner--- name: code-runner description: 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.
| 1 | # Code Runner Skill |
| 2 | |
| 3 | This skill enables you to run code snippets in multiple programming languages directly from the command line. |
| 4 | |
| 5 | ## When to Use This Skill |
| 6 | |
| 7 | Use this skill when: |
| 8 | - The user wants to run or execute a code snippet |
| 9 | - Testing algorithm implementations or logic |
| 10 | - Verifying expected output of code |
| 11 | - Running quick scripts or one-liners |
| 12 | - Checking syntax or runtime behavior |
| 13 | - Demonstrating code functionality |
| 14 | |
| 15 | ## Supported Languages |
| 16 | |
| 17 | The following languages are supported (requires the interpreter/compiler to be installed): |
| 18 | |
| 19 | | Language | Command | File Extension | |
| 20 | |----------|---------|----------------| |
| 21 | | JavaScript | `node` | `.js` | |
| 22 | | TypeScript | `ts-node` | `.ts` | |
| 23 | | Python | `python` | `.py` | |
| 24 | | Java | `java` (compile & run) | `.java` | |
| 25 | | C | `gcc` (compile & run) | `.c` | |
| 26 | | C++ | `g++` (compile & run) | `.cpp` | |
| 27 | | Go | `go run` | `.go` | |
| 28 | | Rust | `rustc` (compile & run) | `.rs` | |
| 29 | | Ruby | `ruby` | `.rb` | |
| 30 | | PHP | `php` | `.php` | |
| 31 | | Perl | `perl` | `.pl` | |
| 32 | | Lua | `lua` | `.lua` | |
| 33 | | R | `Rscript` | `.r` | |
| 34 | | Swift | `swift` | `.swift` | |
| 35 | | Kotlin | `kotlin` | `.kts` | |
| 36 | | Scala | `scala` | `.scala` | |
| 37 | | Groovy | `groovy` | `.groovy` | |
| 38 | | Dart | `dart` | `.dart` | |
| 39 | | Julia | `julia` | `.jl` | |
| 40 | | Haskell | `runhaskell` | `.hs` | |
| 41 | | Clojure | `clojure` | `.clj` | |
| 42 | | F# | `dotnet fsi` | `.fsx` | |
| 43 | | C# | `dotnet script` | `.csx` | |
| 44 | | PowerShell | `pwsh` | `.ps1` | |
| 45 | | Bash | `bash` | `.sh` | |
| 46 | | Batch | `cmd /c` | `.bat` | |
| 47 | | CoffeeScript | `coffee` | `.coffee` | |
| 48 | | Crystal | `crystal` | `.cr` | |
| 49 | | Elixir | `elixir` | `.exs` | |
| 50 | | Nim | `nim compile --run` | `.nim` | |
| 51 | | OCaml | `ocaml` | `.ml` | |
| 52 | | Racket | `racket` | `.rkt` | |
| 53 | | Scheme | `scheme` | `.scm` | |
| 54 | | Lisp | `sbcl --script` | `.lisp` | |
| 55 | |
| 56 | See [references/LANGUAGES.md](references/LANGUAGES.md) for detailed language configuration. |
| 57 | |
| 58 | ## How to Run Code |
| 59 | |
| 60 | ### Step 1: Identify the Language |
| 61 | |
| 62 | Determine the programming language from: |
| 63 | - User's explicit request (e.g., "run this Python code") |
| 64 | - File extension if provided |
| 65 | - Code syntax patterns |
| 66 | |
| 67 | ### Step 2: Execute Using the Runner Script |
| 68 | |
| 69 | **⚠️ Important for AI Agents**: Use stdin to avoid escaping issues with quotes, backslashes, and special characters. |
| 70 | |
| 71 | **Recommended Method (stdin):** |
| 72 | ```bash |
| 73 | echo "<code>" | node scripts/run-code.cjs <languageId> |
| 74 | ``` |
| 75 | |
| 76 | **Alternative Method (CLI argument - for simple code only):** |
| 77 | ```bash |
| 78 | node scripts/run-code.cjs <languageId> "<code>" |
| 79 | ``` |
| 80 | |
| 81 | **Example - JavaScript:** |
| 82 | ```bash |
| 83 | echo "console.log('Hello, World!')" | node scripts/run-code.cjs javascript |
| 84 | ``` |
| 85 | |
| 86 | **Example - Python:** |
| 87 | ```bash |
| 88 | echo "print('Hello, World!')" | node scripts/run-code.cjs python |
| 89 | ``` |
| 90 | |
| 91 | **Example - Java (multi-line):** |
| 92 | ```bash |
| 93 | echo "public class Test { |
| 94 | public static void main(String[] args) { |
| 95 | System.out.println(\"Hello from Java!\"); |
| 96 | } |
| 97 | }" | node scripts/run-code.cjs java |
| 98 | ``` |
| 99 | |
| 100 | **Example - Multi-line code from variable:** |
| 101 | ```bash |
| 102 | # In bash |
| 103 | CODE='import math |
| 104 | print("Pi:", math.pi) |
| 105 | print("Result:", math.factorial(5))' |
| 106 | echo "$CODE" | node scripts/run-code.cjs python |
| 107 | |
| 108 | # In PowerShell (inline here-string) |
| 109 | @" |
| 110 | import math |
| 111 | print("Pi:", math.pi) |
| 112 | print("Result:", math.factorial(5)) |
| 113 | "@ | node scripts/run-code.cjs python |
| 114 | ``` |
| 115 | |
| 116 | ### Step 3: Return Results |
| 117 | |
| 118 | - Show the output (stdout) to the user |
| 119 | - If there are errors (stderr), explain what went wrong |
| 120 | - Suggest fixes for common errors |
| 121 | |
| 122 | ## Platform Notes |
| 123 | |
| 124 | ### Windows |
| 125 | - Use `cmd /c` for batch scripts |
| 126 | - PowerShell scripts require `pwsh` or `powershell` |
| 127 | - Path separators use backslash `\` |
| 128 | |
| 129 | ### macOS / Linux |
| 130 | - Bash scripts work natively |
| 131 | - Swift available on macOS |
| 132 | - Use `#!/usr/bin/env` shebang for portable scripts |
| 133 | |
| 134 | ## Error Handling |
| 135 | |
| 136 | Common issues and solutions: |
| 137 | |
| 138 | 1. **Command not found**: The language interpreter is not installed or not in PATH |
| 139 | - Suggest installing the required runtime |
| 140 | - Provide installation instructions |
| 141 | |
| 142 | 2. **Syntax errors**: Code has syntax issues |
| 143 | - Show the error message |
| 144 | - Point to the line number if available |
| 145 | |
| 146 | 3. **Runtime errors**: Code runs but fails during execution |
| 147 | - Display the stack trace |
| 148 | - Explain the error type |
| 149 | |
| 150 | 4. **Timeout**: Code takes too long (default: 30 seconds) |
| 151 | - Warn about infinite loops |
| 152 | - Suggest optimizations |
| 153 | |
| 154 | ## Security Considerations |
| 155 | |
| 156 | ⚠️ **Important**: Running arbitrary code can be dangerous. Always: |
| 157 | |
| 158 | 1. Review the code before execution |
| 159 | 2. Be cautious with code that: |
| 160 | - Accesses the file system |
| 161 | - Makes network requests |
| 162 | - Executes system commands |
| 163 | - Modifies environment variables |
| 164 | 3. Consider running in a sandboxed environmen |