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...

formulahendry

@formulahendry

What This Skill Does

Executes code snippets in over 30 programming languages including JavaScript, Python, TypeScript, Java, C, C++, Go, Rust, Ruby, and PHP. Supports both interpreted and compiled languages, returning stdout output or error messages.

Replaces manually setting up and running code in separate language environments by providing a single unified command to execute snippets in any supported language.

When to Use It

  • Test a Python algorithm to verify its output
  • Run a JavaScript one-liner to check syntax or behavior
  • Compile and execute a C program to debug logic errors
  • Execute a Ruby script to demonstrate a code concept
  • Run a Go snippet to validate a function implementation
  • Quickly check the output of a TypeScript expression

Install

$ openclaw skills install @formulahendry/code-runner

Code Runner Skill

This skill enables you to run code snippets in multiple programming languages directly from the command line.

When to Use This Skill

Use this skill when:

  • The user wants to run or execute a code snippet
  • Testing algorithm implementations or logic
  • Verifying expected output of code
  • Running quick scripts or one-liners
  • Checking syntax or runtime behavior
  • Demonstrating code functionality

Supported Languages

The following languages are supported (requires the interpreter/compiler to be installed):

LanguageCommandFile Extension
JavaScriptnode.js
TypeScriptts-node.ts
Pythonpython.py
Javajava (compile & run).java
Cgcc (compile & run).c
C++g++ (compile & run).cpp
Gogo run.go
Rustrustc (compile & run).rs
Rubyruby.rb
PHPphp.php
Perlperl.pl
Lualua.lua
RRscript.r
Swiftswift.swift
Kotlinkotlin.kts
Scalascala.scala
Groovygroovy.groovy
Dartdart.dart
Juliajulia.jl
Haskellrunhaskell.hs
Clojureclojure.clj
F#dotnet fsi.fsx
C#dotnet script.csx
PowerShellpwsh.ps1
Bashbash.sh
Batchcmd /c.bat
CoffeeScriptcoffee.coffee
Crystalcrystal.cr
Elixirelixir.exs
Nimnim compile --run.nim
OCamlocaml.ml
Racketracket.rkt
Schemescheme.scm
Lispsbcl --script.lisp

See references/LANGUAGES.md for detailed language configuration.

How to Run Code

Step 1: Identify the Language

Determine the programming language from:

  • User's explicit request (e.g., "run this Python code")
  • File extension if provided
  • Code syntax patterns

Step 2: Execute Using the Runner Script

⚠️ Important for AI Agents: Use stdin to avoid escaping issues with quotes, backslashes, and special characters.

Recommended Method (stdin):

echo "<code>" | node scripts/run-code.cjs <languageId>

Alternative Method (CLI argument - for simple code only):

node scripts/run-code.cjs <languageId> "<code>"

Example - JavaScript:

echo "console.log('Hello, World!')" | node scripts/run-code.cjs javascript

Example - Python:

echo "print('Hello, World!')" | node scripts/run-code.cjs python

Example - Java (multi-line):

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

Example - Multi-line code from variable:

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

# In PowerShell (inline here-string)
@"
import math
print("Pi:", math.pi)
print("Result:", math.factorial(5))
"@ | node scripts/run-code.cjs python

Step 3: Return Results

  • Show the output (stdout) to the user
  • If there are errors (stderr), explain what went wrong
  • Suggest fixes for common errors

Platform Notes

Windows

  • Use cmd /c for batch scripts
  • PowerShell scripts require pwsh or powershell
  • Path separators use backslash \

macOS / Linux

  • Bash scripts work natively
  • Swift available on macOS
  • Use #!/usr/bin/env shebang for portable scripts

Error Handling

Common issues and solutions:

  1. Command not found: The language interpreter is not installed or not in PATH

    • Suggest installing the required runtime
    • Provide installation instructions
  2. Syntax errors: Code has syntax issues

    • Show the error message
    • Point to the line number if available
  3. Runtime errors: Code runs but fails during execution

    • Display the stack trace
    • Explain the error type
  4. Timeout: Code takes too long (default: 30 seconds)

    • Warn about infinite loops
    • Suggest optimizations

Security Considerations

⚠️ Important: Running arbitrary code can be dangerous. Always:

  1. Review the code before execution
  2. Be cautious with code that:
    • Accesses the file system
    • Makes network requests
    • Executes system commands
    • Modifies environment variables
  3. Consider running in a sandboxed environment for untrusted code

Examples

Example 1: Run a JavaScript calculation

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

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

Example 2: Run Python with imports

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

Output: 3628800

Example 3: Test a Go function

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

Output: Hello from Go!

Related skills

JavaScript

@ivangdavila

Writes, debugs, and reviews JavaScript: async and the event loop, coercion, closures, dates, Unicode, regex, and modern ES2023+ APIs. Use when JS throws TypeError or "undefined is not a function", a promise never settles or a rejection goes unhandled, NaN or [object Object] appears, dates shift by a day, sorting or equality misbehaves, memory grows, a regex hangs, JSON loses precision, a Node process won't exit or ignores signals, or fetch doesn't reject on a 404; also when choosing data structures, handling errors, profiling slow code, or checking whether a feature is safe for a target Node or browser version. Covers Node and browser runtime edges. Not for TypeScript type-system design or framework internals.

53.9k

JavaScript

@wscats

A comprehensive JavaScript style guide skill. When activated, it provides best-practice JavaScript coding conventions and generates code that strictly follow...

117.0k

TypeScript

@ivangdavila

Writes, reviews, and debugs type-safe TypeScript: type errors, narrowing, generics, tsconfig strictness, and declaration files. Use when a build hits type errors ("not assignable", "possibly undefined", "excessively deep", "cannot find module"), when eliminating any or unchecked as casts, designing generics or discriminated unions, writing .d.ts files or typing untyped npm packages, configuring tsconfig or module resolution, fixing ESM/CJS import crashes ("ERR_REQUIRE_ESM", "x is not a function"), validating API or JSON data at runtime, migrating JavaScript to TypeScript or upgrading the TypeScript version, or when tsc or the editor gets slow or runs out of memory.

65.8k

Humanizer

@biostartechnology

Remove signs of AI-generated writing from text. Use when editing or reviewing text to make it sound more natural and human-written. Based on Wikipedia's comprehensive "Signs of AI writing" guide. Detects and fixes patterns including: inflated symbolism, promotional language, superficial -ing analyses, vague attributions, em dash overuse, rule of three, AI vocabulary words, negative parallelisms, and excessive conjunctive phrases.

703126k

TypeScript

@wscats

Provide best-practice coding conventions and generate standards-compliant TypeScript code.

105.4k

NodeJS

@ivangdavila

Builds, debugs, and hardens Node.js servers, CLIs, and npm packages: async, modules, streams, memory, and process lifecycle. Use when writing or reviewing code that runs on Node, when a process hangs or refuses to exit, leaks memory, gets OOM-killed, pins one CPU core at 100%, or dies on an unhandled rejection; when the error reads EADDRINUSE, EMFILE, ECONNRESET, ERR_MODULE_NOT_FOUND, ERR_REQUIRE_ESM, or "__dirname is not defined"; when import and require interop breaks, streams buffer everything in RAM, a server returns intermittent 502s behind a load balancer, or SIGTERM drops in-flight requests; when npm install, lockfiles, peer dependencies, workspaces, native module builds, or publishing misbehave; when a suite passes locally and fails in CI; or when containerizing, profiling, and shutting down a service cleanly. Not for browser-only JavaScript, TypeScript type-system design, or the Bun and Deno runtimes.

54.0k