Skip to content

docs(dev): verify code-executor guide against code and unmark migrated (#206) - #213

Open
Fire162 wants to merge 2 commits into
antiv:mainfrom
Fire162:docs/code-executor-clean
Open

Fire162 wants to merge 2 commits into
antiv:mainfrom
Fire162:docs/code-executor-clean

Conversation

@Fire162

@Fire162 Fire162 commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

Part of #206.

Summary of Changes

  • Verified docs/dev/code-executor.md against the underlying implementation files:
    • shared/utils/tools/code_executor_tools.py: confirmed parameter definitions for execute_python_code and execute_shell_command, timeouts (default 30s, max 120s), output capping (50,000 chars), isolated temporary directory lifecycle (mate_exec_...), and return dictionary structures.
    • shared/utils/tools/tool_factory.py: confirmed widget key safety guard (_agent_has_widget_key refusing executor on agents with widget keys unless MATE_ALLOW_CODE_EXECUTOR_ON_WIDGET=true).
  • Removed status: migrated from frontmatter in docs/dev/code-executor.md.
  • Ran python3 scripts/gen_docs.py --check (passes with 0 errors).

@antiv antiv left a comment •

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Removing status: migrated says the page has been checked, but a few statements in it don't match the code yet, so the guide itself needs edits in this PR:

  1. "Isolated temp directory per run (cleaned up after)": the finally block only unlinks script.py and calls os.rmdir(tmp_dir). If the script writes any file, rmdir fails silently and the mate_exec_* directory stays. execute_shell_command creates no temp dir at all and runs in the server's working directory. Please also drop "isolated"; the tool is not a sandbox.
  2. "System python (same as the server process)": the code runs ["python", script_path], i.e. whatever python is first on PATH, not sys.executable. It can be a different interpreter, or missing where only python3 exists.
  3. {"code_executor": {"timeout": 60}}: saving Tool Configuration in the dashboard writes code_executor = true (agent-tools.js:85), which drops the custom timeout. Worth saying.
  4. "Timed-out processes are killed": for execute_shell_command (shell=True) only /bin/sh is killed; processes it started can keep running.
  5. Error returns: empty input and exceptions return {"status": "error", "error_message": ...} without stdout/stderr. Document that shape too.
  6. covers: should also list shared/utils/tools/tool_factory.py (the widget-key check the guide describes), and the dashboard warning in templates/dashboard/modals/config_modals.html / static/js/agent-tools.js (step 3 in #206).
  7. Nit: the override accepts 1, true or yes.

Then run python scripts/gen_docs.py --check again and I'll take another look.

@Fire162

Fire162 commented Oct 11, 2026

Copy link
Copy Markdown
Contributor Author

Thank you for the detailed feedback. I have updated docs/dev/code-executor.md to address all 7 points:

  1. Clarified that mate_exec_* cleanup removes script.py and tries os.rmdir, so additional files written into the temp dir cause rmdir to fail silently and leave the directory.
  2. Clarified Python binary resolution uses the first python found on PATH, which may differ from sys.executable.
  3. Documented dashboard tool config UI behavior: saving writes code_executor = true, resetting custom timeouts to the 30s default.
  4. Documented shell execution process management: only the spawned /bin/sh process is killed on timeout, leaving any child processes running.
  5. Added the explicit error return shape {"status": "error", "error_message": ...} on validation failure or exceptions.
  6. Expanded covers: frontmatter to include tool_factory.py, config_modals.html, and agent-tools.js.
  7. Corrected the MATE_ALLOW_CODE_EXECUTOR_ON_WIDGET documentation to note that 1, true, or yes skip the check.

@antiv

antiv commented Oct 11, 2026

Copy link
Copy Markdown
Owner

Thanks, all seven points are in. Two small things before merging:

  1. "Subprocesses inherit os.environ with PYTHONDONTWRITEBYTECODE=1" is only true for execute_python_code; execute_shell_command passes no env, so the shell gets plain os.environ.
  2. "Scripts have access to whatever packages are installed in the server's Python environment" now contradicts the PATH note: they get the packages of whichever python is first on PATH.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants