code-runner
npx machina-cli add skill next-open-ai/openclawx/code-runner --openclawCode Runner Skill
Use this skill to quickly execute a piece of code to test logic, write a script for the user, or run built-in system tools.
Workflow
- Determine the language required (Node.js, Python, Shell, Go, etc.).
- Write the code snippet to a temporary file using the
writetool (e.g., in/tmp/test-script.js). - Use the
bashtool to execute the script (e.g.,node /tmp/test-script.js). - Capture the standard output and standard error.
- Provide the execution result to the user.
- Clean up the temporary file using
bash(rm /tmp/test-script.js).
Example Usage
If the user asks "How do I reverse a string in JavaScript? Show me.", write a script with the solution, run it to verify it works, and show them both the code and the verified output.
Source
git clone https://github.com/next-open-ai/openclawx/blob/main/presets/workspaces/code-assistant/skills/code-runner/SKILL.mdView on GitHub Overview
Code-runner lets you quickly test code snippets by saving them to a temporary file and executing them with the correct runtime (Node.js, Python, Shell, Go, etc.). It captures stdout and stderr to verify results and then cleans up the temporary file to keep the workspace tidy.
How This Skill Works
First, determine the required language (Node.js, Python, Shell, Go, etc.). Then write the snippet to a temporary file in /tmp using the write tool (e.g., /tmp/test-script.js). Next, execute the script with the matching command via bash (e.g., node /tmp/test-script.js). Finally, capture stdout and stderr, present the results, and remove the temporary file.
When to Use It
- Quickly test a short snippet in the user's chosen language (Node, Python, Shell, Go) to verify logic.
- Demonstrate a solution by producing runnable code and showing the verified output.
- Debug a small script during a chat by executing it step-by-step and inspecting stdout/stderr.
- Validate results of simple algorithms or utilities without leaving the chat.
- Provide educational, runnable examples that users can copy and run locally.
Quick Start
- Step 1: Write your code to a temp file using the write tool, e.g., /tmp/test-script.js.
- Step 2: Run it with the appropriate launcher via bash, e.g., node /tmp/test-script.js.
- Step 3: Review stdout/stderr, then delete the temp file with rm /tmp/test-script.js.
Best Practices
- Use self-contained snippets with all necessary imports and dependencies included.
- Write to a unique file path in /tmp to avoid collisions (e.g., /tmp/test-script-123.js).
- Check that the target language runtime is available before running (e.g., node, python).
- Capture and clearly present both stdout and stderr, along with exit status.
- Ensure cleanup happens in all cases, even if execution fails.
Example Use Cases
- JavaScript: reverse a string and show the verified output.
- Python: compute the factorial of 5 and print 120.
- Go: print a small message or compute a value using a tiny program.
- Shell: list files in a directory and return the line count.
- Node.js: read a short snippet and log the processed result.