- Add code-interpreter, kokoro-tts, remotion-best-practices, research-to-paper-slides, summarize, tavily-tool to source repo - skill-review: add main/xiaoming agent mapping in handler.ts + SKILL.md - tts-voice: handler.ts updates from agent workspace Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
5.4 KiB
Code Interpreter
Run local Python code through the bundled runner.
Safety boundary
This is local execution, not a hardened container. Treat it as a convenience tool for trusted, low-risk tasks.
Always:
- Keep work inside the OpenClaw workspace when possible.
- Prefer reading/writing files under the current task directory or an explicit artifact directory.
- Keep timeouts short by default.
- Avoid network access unless the user explicitly asks and the task truly needs it.
- Do not execute untrusted code copied from the web or other people.
- Do not expose secrets, tokens, SSH keys, browser cookies, or system files to the script.
Do not use this skill for:
- system administration
- package installation loops
- long-running servers
- privileged operations
- destructive file changes outside the workspace
- executing arbitrary third-party code verbatim
Runner
Run from the OpenClaw workspace:
python3 {baseDir}/scripts/run_code.py --code 'print(2 + 2)'
Or pass a script file:
python3 {baseDir}/scripts/run_code.py --file path/to/script.py
Or pipe code via stdin:
cat my_script.py | python3 {baseDir}/scripts/run_code.py --stdin
Useful options
# set timeout seconds (default 20)
python3 {baseDir}/scripts/run_code.py --code '...' --timeout 10
# run from a specific working directory inside workspace
python3 {baseDir}/scripts/run_code.py --file script.py --cwd /home/selig/.openclaw/workspace/project
# keep outputs in a known artifact directory inside workspace
python3 {baseDir}/scripts/run_code.py --file script.py --artifact-dir /home/selig/.openclaw/workspace/.tmp/my-analysis
# save full stdout / stderr
python3 {baseDir}/scripts/run_code.py --code '...' --stdout-file out.txt --stderr-file err.txt
Built-in environment
The runner uses the dedicated interpreter at:
/home/selig/.openclaw/workspace/.venv-code-interpreter/bin/python(use the venv path directly; do not resolve the symlink to system Python)
This keeps plotting/data-analysis dependencies stable without touching the system Python.
The runner exposes these variables to the script:
OPENCLAW_WORKSPACECODE_INTERPRETER_RUN_DIRCODE_INTERPRETER_ARTIFACT_DIR
It also writes a helper file in the run directory:
from ci_helpers import save_text, save_json
Use those helpers to save artifacts into CODE_INTERPRETER_ARTIFACT_DIR.
V4 automatic data analysis
For automatic profiling/report generation from a local data file, use:
scripts/analyze_data.py- Reference:
references/v4-usage.md
This flow is ideal when the user wants a fast "analyze this CSV/JSON/Excel and give me a report + plots" result.
Output
The runner prints compact JSON:
{
"ok": true,
"exitCode": 0,
"timeout": false,
"runDir": "...",
"artifactDir": "...",
"packageStatus": {"pandas": true, "numpy": true, "matplotlib": false},
"artifacts": [{"path": "...", "bytes": 123}],
"stdout": "...",
"stderr": "..."
}
Workflow
- Decide whether the task is a good fit for local trusted execution.
- Write the smallest script that solves the problem.
- Use
--artifact-dirwhen the user may want generated files preserved. - Run with a short timeout.
- Inspect
stdout,stderr, andartifacts. - If producing files, mention their exact paths in the reply.
Patterns
Exact calculation
Use a one-liner with --code.
File analysis
Read input files from workspace, then write summaries/derived files back to artifactDir.
Automatic report bundle
When the user wants a quick profiling pass, run scripts/analyze_data.py against the file and return the generated summary.json, report.md, preview.csv, and any PNG plots.
Table inspection
Prefer pandas when available; otherwise fall back to csv/json stdlib.
Plotting
If matplotlib is available, write PNG files to artifactDir. Use a forced CJK font strategy for Chinese charts. The bundled default is Google Noto Sans CJK TC under assets/fonts/ when present, then system fallbacks. Apply the chosen font not only via rcParams but also directly to titles, axis labels, tick labels, and legend text through FontProperties. This avoids tofu/garbled Chinese and suppresses missing-glyph warnings reliably. If plotting is unavailable, continue with tabular/text output.
Reusable logic
Write a small .py file in the current task area, run with --file, then keep it if it may be reused.
Notes
- The runner launches
python3 -Bwith a minimal environment. - It creates an isolated temp run directory under
workspace/.tmp/code-interpreter-runs/. stdout/stderrare truncated in the JSON preview if very large; save to files when needed.MPLBACKEND=Aggis set so headless plotting works when matplotlib is installed.- If a task needs stronger isolation than this local runner provides, do not force it—use a real sandbox/container approach instead.