agent-zero/plugins/_code_execution
Alessandro ad5bebbea5 Send complete SSH commands without blocking the event loop
Paramiko Channel.send can accept only part of a command. Ignoring its byte
count truncated large inputs, including heredocs whose closing delimiters
never reached the shell.

Use sendall through asyncio.to_thread and route shell initialization through
the same send path. Close the SSH connection when an in-flight send is
cancelled so partial input cannot contaminate later commands. Cancellation
intentionally discards that SSH session and its shell state.

Add regressions for multi-packet Unicode delivery and blocked-window
responsiveness/cancellation, and document the SSH send contract.

Validation: 24 focused tests passed. Real Paramiko transport and container
OpenSSH probes delivered complete large single/nested heredocs and preserved
shell state across terminal, Python and Node.js calls. No local TTY, prompt
readiness, tool-dispatch, or platform-specific heredoc workaround changes.
2026-10-06 18:49:30 +02:00
..
extensions Fix flashing process groups during memory search 2026-09-16 16:17:37 +02:00
helpers Send complete SSH commands without blocking the event loop 2026-10-06 18:49:30 +02:00
prompts fix(prompts): validate examples and sharpen skill descriptions 2026-09-08 02:37:44 +02:00
tools Keep parallel terminal jobs alive until their commands finish 2026-09-06 21:01:11 +02:00
webui generated logos for builtin plugins 2026-03-19 17:35:03 +01:00
AGENTS.md Send complete SSH commands without blocking the event loop 2026-10-06 18:49:30 +02: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 Handle shell/SSH process exits as completion 2026-07-20 17:04:05 +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.
    • Groups multi-line terminal input in the current shell so only the final prompt marks the command complete.
  • 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.
    • Detects local shell exit and SSH channel termination when strict mode, exit, or a lost connection prevents a final prompt from appearing.
  • 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.