Skip to main content

Module python

Module python 

Source
Expand description

A plugin’s declared Python tools (tools[].run): the model’s arguments go to the script as JSON on stdin; what it prints (plain text, or {"text": …, "files": […]}) goes back. Settings arrive as environment variables, plus HOB_CHAT_DIR and HOB_PLUGIN_DIR (and BYOB_* aliases).

Given a Sandbox (PythonTool::with_sandbox), scripts run confined by byob-sandbox (run_script_sandboxed: workspace + temp writable, plugin folder readable, network only if the plugin declares permissions.network). Without one they’re a plain child process (run_script_unsandboxed). Either way: timeout, bounded output, process-group kill, and Access::Execute so the permission gate asks.

Structs§

PythonTool
A plugin’s Python tool.
ScriptOutcome
ScriptRun
One script run.

Constants§

MAX_SCRIPT_OUTPUT
Most bytes kept from each of stdout and stderr.
SCRIPT_TIMEOUT
hob’s limit for a plugin tool.

Functions§

default_python
The interpreter a Python tool runs with, as a command prefix.
fill_title
"Converted {amount} {from}" + args → "Converted 5 EUR"; unknown keys stay.
python_tools
The Python tools plugin declares, named as declared (so the plugin’s prompt still matches) or <plugin>__<tool> when that name is taken. Tools whose script is missing are left out (the plugin’s problems say so).
python_tools_in
python_tools whose scripts run in sandbox (when given).
run_script_sandboxed
Run a script in sandbox: read the system, the plugin folder and the interpreter; read+write run.cwd (the workspace) and a private temp folder; network only if network. The environment is reset to a minimal one plus run.env.
run_script_unsandboxed
Run a script as a plain child process: no sandbox. Kills it (and its process group) on timeout or when cancelled() turns true. Err only when it couldn’t start.