π Code Runner Skill
Overview
This skill enables the LLM to help users execute Python scripts located in the file system by producing a strictly-formatted JSON output that describes the script to run. The JSON output is then parsed by the code_runner_execute skill to run the script via subprocess.run() and return the output.
The default working directory is the current directory (./) unless the user specifies otherwise.
Skill Name
code-runner
When to Use This Skill
Invoke this skill whenever the user's request implies executing a Python script. Look for phrases such as:
- "run the script ..."
- "execute ..."
- "run a Python script ..."
- "run this code ..."
- "python ..."
- "call the script ..."
Do NOT use this skill when the user wants to:
- Create or modify files β use
file-creator/file-changer. - Read files β use
file-reader. - Make HTTP requests β use
curl. - Execute a raw shell command that is not a Python script β use
cmd-runner.
What the LLM Must Do
When the skill is triggered, the LLM must:
Extract the following from the user's request (asking clarifying questions only if truly ambiguous):
- scriptPath or fileName (required): The path (directory + filename) of the Python script to execute.
- method (optional): The execution method. Defaults to
script(running the whole script) when method is empty. Possible values:script(default),function(run a specific function). - args (optional): Command-line arguments to pass to the script (or the target function/statement name when method is
function/statement). - timeout (optional): Maximum execution time in seconds. Defaults to
30. - shelltype (optional): The type of shell used to invoke Python. Possible values: "bash" (Linux/Unix default), "maccmd" (macOS terminal), "windowsbat" (Windows Command Prompt), "windowsps" (Windows PowerShell). If not specified, auto-detect based on the OS.
- env (optional): A dictionary of environment variables to set.
- description (optional): One-line summary of the task.
- sequential (optional): If the output is needed as input for a follow-up AI task.
- prompt (optional): Follow-up prompt for all of the following tasks when
sequentialis set.
Produce a response containing a single pure JSON object that STRICTLY follows the schema below. No code fences, no extra prose.
Required JSON Output Schema
The LLM's response MUST be a pure JSON string with no code blocks.
{
"action": "run_code_script",
"thinking": "<ai-thinking-trace>",
"sequential": {
"prompt": "Follow-up prompt for all of the following tasks."
},
"properties": [
{ "name": "scriptPath", "value": "path/to/script.py" },
{ "name": "fileName", "value": "script.py" },
{ "name": "args", "value": "" },
{ "name": "timeout", "value": "30" },
{ "name": "shelltype", "value": "one of bash, maccmd, windowsbat, windowsps according to the os" },
{ "name": "env", "value": "{}" },
{ "name": "description","value": "" }
]
}
Field Rules
| Field | Type | Required | Notes |
|---|---|---|---|
action |
string | Yes | Must be exactly "run_code_script". |
scriptPath |
string | Yes | The directory portion of the script path, or full path. Must be non-empty. |
fileName |
string | Yes | The Python file name including .py. May be omitted if included in scriptPath. |
method |
string | No | Execution method: script (default), function |
args |
string | No | Command-line arguments passed to the script, or target name for function/statement. |
timeout |
string | No | Timeout in seconds as string. Default "30". Max "120". |
shelltype |
string | No | Type of shell: "bash", "maccmd", "windowsbat", "windowsps". Defaults to OS-based auto-detect. |
env |
string | No | JSON-encoded dictionary of environment variables. Default "{}". |
description |
string | No | Human-readable purpose of the execution. |
sequential |
object | No | Whether the output should feed a follow-up AI task. Default null. |
prompt |
string | No | Follow-up prompt for all of following tasks when sequential is set. |
Formatting Requirements
- The JSON output must be valid JSON (parseable by
json.loads). - All string values must properly escape special characters (
",\, newline as\n, tab as\t). envmust be a valid JSON object string (e.g.,{"PATH": "/usr/bin"}).- Do NOT emit multiple
code-runnerpayloads in a single response. - If the user does not specify a script path, do NOT execute this skill β ask for the script path first or produce an empty action.
Response Pattern for the LLM
A typical assistant reply should look like the following. No other output is needed. Output must be in pure JSON format.
{ "action": "run_code_script", "thinking": "User wants to run a Python script.", "sequential": { "prompt":"Follow-up prompt for all of following tasks" }, "properties": [ { "name": "scriptPath", "value": "./scripts/" }, { "name": "fileName", "value": "hello.py" }, { "name": "args", "value": "" }, { "name": "timeout", "value": "30" }, { "name": "shelltype", "value": "bash" }, { "name": "env", "value": "{}" }, { "name": "description","value": "Run hello.py" } ] }
Decision Logic
User Prompt
|
+-- Does the request imply executing a Python script?
| |
| +-- YES --> Extract scriptPath/fileName/method/args/timeout/flags --> Emit ONE `code-runner` JSON payload
| |
| +-- NO --> Do not use this skill
Examples
Example 1: Simple script run (Linux/macOS)
User: "Run scripts/hello.py."
LLM emits:
{
"action": "run_code_script",
"thinking": "User wants to run a Python script.",
"properties": [
{ "name": "scriptPath", "value": "scripts/" },
{ "name": "fileName", "value": "hello.py" },
{ "name": "method", "value": "run" },
{ "name": "args", "value": "" },
{ "name": "timeout", "value": "30" },
{ "name": "shelltype", "value": "bash" },
{ "name": "env", "value": "{}" },
{ "name": "description", "value": "Run hello.py" }
]
}
Example 2: Script run with arguments
User: "Run tools/parse.py with arguments --input data.txt."
LLM emits:
{
"action": "run_code_script",
"thinking": "User wants to run a Python script with command-line arguments.",
"properties": [
{ "name": "scriptPath", "value": "tools/" },
{ "name": "fileName", "value": "parse.py" },
{ "name": "args", "value": "--input data.txt" },
{ "name": "timeout", "value": "30" },
{ "name": "shelltype", "value": "bash" },
{ "name": "env", "value": "{}" },
{ "name": "description", "value": "Run parse.py with arguments" }
]
}
Example 3: Script run with environment variables
User: "Run env_test.py with MY_VAR=hello."
LLM emits:
{
"action": "run_code_script",
"thinking": "User wants to run a script with custom environment variables.",
"properties": [
{ "name": "scriptPath", "value": "./" },
{ "name": "fileName", "value": "env_test.py" },
{ "name": "args", "value": "" },
{ "name": "timeout", "value": "30" },
{ "name": "shelltype", "value": "bash" },
{ "name": "env", "value": "{\"MY_VAR\": \"hello\"}" },
{ "name": "description", "value": "Test environment variable" }
]
}
Example 4: Long-running script with timeout
User: "Run long_task.py but timeout after 10 seconds."
LLM emits:
{
"action": "run_code_script",
"thinking": "User wants a script that might take long, with a short timeout.",
"properties": [
{ "name": "scriptPath", "value": "./" },
{ "name": "fileName", "value": "long_task.py" },
{ "name": "args", "value": "" },
{ "name": "timeout", "value": "10" },
{ "name": "shelltype", "value": "bash" },
{ "name": "env", "value": "{}" },
{ "name": "description", "value": "Test timeout" }
]
}
Example 5: Execute a specific function
User: "Run the function main in utils.py."
LLM emits:
{
"action": "run_code_script",
"thinking": "User wants to execute a specific function in a Python script.",
"properties": [
{ "name": "scriptPath", "value": "./" },
{ "name": "fileName", "value": "utils.py" },
{ "name": "method", "value": "function" },
{ "name": "args", "value": "main" },
{ "name": "timeout", "value": "30" },
{ "name": "shelltype", "value": "bash" },
{ "name": "env", "value": "{}" },
{ "name": "description", "value": "Run main() function in utils.py" }
]
}
Safety Guidelines
- Never execute Python scripts that could harm the system (e.g., scripts containing
os.remove,shutil.rmtree,subprocesscalls torm -rf /,dd,format C:, fork bombs, etc.). Block such scripts. - Refuse scripts that attempt to access sensitive paths (e.g.,
C:\Windows\,/etc/shadow,~/.ssh/). - Enforce a reasonable timeout (default 30s, max 120s).
- Limit the output size to prevent excessive output (e.g., 1MB max stdout/stderr).
- Always echo the JSON payload so the user can review before execution.
- Do not execute scripts that modify system configuration or install software without explicit user confirmation.
Executable Skills
code_runner_execute
Parses a code-runner JSON payload and executes the Python script.
Parameters:
json_payload(str): The JSON string produced by the LLM.
Behavior:
- Validates the schema (including
shelltypeif provided). - Checks for dangerous script contents and refuses to execute them.
- Resolves the script path using
scriptPathandfileName. - Uses the specified
shelltypeto determine the appropriate shell executable for invoking Python:"bash"β runs with/bin/bash(orbashon PATH)."maccmd"β runs with/bin/zsh(macOS default)."windowsbat"β runs withcmd.exe."windowsps"β runs withpowershell.exe.- If not specified, auto-detects based on
sys.platform.
- Runs
python <scriptPath/fileName> <args>viasubprocess.run(). - Supports execution methods:
run(whole script),function(specific function),statement(specific statement/expression). - Sets environment variables if
envis provided. - Enforces timeout.
- Returns a JSON string containing
stdout,stderr, andreturncode. [axle] 2026-08-22 11:12:37 continue: False [axle] 2026-08-22 11:12:37 result: User Prompt | +-- Does the request imply executing a Python script? | | | +-- YES --> Extract scriptPath/fileName/method/args/timeout/flags --> Emit ONEcode-runnerJSON payload | | | +-- NO --> Do not use this skill