agent-zero/plugins/_code_execution
shisan 528c33b7ef Disable pagers in non-interactive code execution shells
The code execution tool runs commands inside TTY-backed shells (local PTY and
remote SSH). Commands like `git diff`/`git log` detect the TTY and pipe output
through a pager (more/less). These shells never receive interactive input, so
the pager blocks forever and spins at 100% CPU per process — on a 16-core host
5 pager processes pegged 5 cores for 8+ hours (#1697).

Disable pagers in both session types:
- LocalInteractiveSession: inject PAGER=cat / GIT_PAGER=cat into the TTY env
- SSHInteractiveSession: export the same in the initial shell command

`cat` streams the output through instead of blocking, and also covers other
pager-using tools (man, systemctl, journalctl). Adds regression tests.

Fixes #1697
2026-06-13 21:17:57 +08:00
..
extensions refactor: split system prompt into per-concern extensions with extensibility hooks 2026-03-20 12:12:47 +08:00
helpers Disable pagers in non-interactive code execution shells 2026-06-13 21:17:57 +08:00
prompts Improve coding-agent verification discipline 2026-06-02 09:15:48 +02:00
tools Tune code execution timeouts 2026-06-02 09:15:57 +02:00
webui generated logos for builtin plugins 2026-03-19 17:35:03 +01:00
default_config.yaml Tune code execution timeouts 2026-06-02 09:15:57 +02:00
plugin.yaml refactor - plugin names and builtin plugins 2026-03-10 22:20:53 +01:00
README.md Tune code execution timeouts 2026-06-02 09:15:57 +02:00

Code Execution

Run terminal commands and execute Python or Node.js code through Agent Zero using persistent shell sessions.

What It Does

This plugin provides the code execution tool used by agents for development tasks. It supports:

  • Terminal commands in interactive shell sessions
  • Python execution through ipython -c
  • Node.js execution through node /exe/node_eval.js
  • Persistent sessions keyed by session number
  • Session reset and output retrieval
  • Local or SSH-backed execution depending on plugin configuration

Main Behavior

  • Persistent shells
    • Maintains per-session shell state in agent data so subsequent calls can reuse the same terminal session.
  • Multiple runtimes
    • Dispatches requests based on runtime: terminal, python, nodejs, output, or reset.
  • Remote execution support
    • Can open SSH interactive sessions instead of local shells when configured.
  • Streaming output
    • Continuously reads shell output, updates the current log item, and detects progress while commands are running.
  • Long-running work
    • Keeps normal command execution responsive while giving the output runtime longer polling windows for builds, installs, servers, tests, and training jobs.
  • Safety around running sessions
    • Tracks whether a shell is currently busy and can prevent overlapping commands unless explicitly allowed.

Key Files

  • Tool
    • tools/code_execution_tool.py contains runtime dispatch, session lifecycle, and streaming output logic.
  • Helpers
    • helpers/shell_local.py provides the local interactive shell implementation.
    • helpers/shell_ssh.py provides the SSH-backed interactive shell implementation.
  • Configuration
    • default_config.yaml defines execution, prompt, and timeout settings.
  • Prompts
    • prompts/ contains the response templates shown to the agent.

Configuration Scope

  • Settings section: agent
  • Per-project config: true
  • Per-agent config: true
  • Always enabled: false

Plugin Metadata

  • Name: _code_execution
  • Title: Code Execution
  • Description: Code execution tool supporting terminal, Python, and Node.js runtimes via local TTY or SSH.