hylo.codeagents.motion_scripts¶
Package: hylo-code-agents · Core contracts
motion_scripts ¶
Model-written scripts run in a directory, under a guard, with tool calls served over a pipe (free mode of the motion studio; nothing here is specific to motion).
- check_source: the static check before anything runs: imports from an allow-list or the run directory's lib/ (checked too), no eval / exec / getattr, no dunder or private attributes, no async code.
- ScriptRunner.run(code): saves the script as scripts/turnNN.py and runs it with motion_freerun.py (python -I,
cwd = the run directory, resource limits, an audit hook refusing files outside the directory, processes,
sockets and ctypes). The script talks to
handler(op, args)in this process through two pipes (one JSON line per request and per answer); PermissionError from the handler is reported as a refusal. The time limit excludes the time spent in handler calls. Returns the code-agents BlockResult, so a CodeLoop can drive it. - inside: resolve a path given by a script, refusing anything outside the run directory.
ALLOWED_IMPORTS
module-attribute
¶
ALLOWED_IMPORTS = {'numpy', 'scipy', 'math', 'json', 'statistics', 'itertools', 'functools', 'collections', 'dataclasses', 'typing', 'random', 're', 'copy', 'pathlib', 'studio', 'ops', 'bisect', 'heapq', 'fractions', 'decimal', 'string', 'textwrap', 'operator', 'enum', 'time'}
DENIED_NAMES
module-attribute
¶
DENIED_NAMES = {'eval', 'exec', 'compile', '__import__', 'globals', 'locals', 'vars', 'breakpoint', 'input', 'getattr', 'setattr', 'delattr', 'memoryview', 'help', 'exit', 'quit', 'os', 'sys', 'subprocess', 'socket', 'shutil', 'ctypes', 'importlib', 'builtins', '__builtins__', '__loader__', '__spec__'}
DENIED_ATTRS
module-attribute
¶
DENIED_ATTRS = {'os', 'sys', 'subprocess', 'system', 'popen', 'spawn', 'fork', 'builtins', 'ctypes', 'ctypeslib', 'f2py', 'distutils', 'importlib', 'modules', 'load_library', 'dlopen', 'loader'}
ALLOWED_DUNDERS
module-attribute
¶
ALLOWED_DUNDERS = {'__name__', '__file__', '__doc__', '__init__', '__len__', '__repr__', '__str__', '__iter__', '__getitem__', '__call__', '__eq__', '__lt__', '__main__'}
ScriptRejected ¶
Bases: ValueError
The script failed the static check; nothing ran.
ScriptRunner ¶
ScriptRunner(root: Path, handler: Callable[[str, dict], Any], *, emit: Callable[[dict], None], timeout_s: float = 900.0, python: str | None = None, threads: int = 8)
Runs scripts in root (the CodeLoop's sandbox interface: run(code) -> BlockResult) and serves their
requests with handler(op, args); every script and request is passed to emit for the log.
run ¶
Check, save and run one script; its output, error and time (handler time excluded).
check_source ¶
Raise ScriptRejected listing what the script may not do. Local modules it imports (root/lib/NAME.py) are checked as well.
inside ¶
path (relative to root, or absolute) resolved; PermissionError if it leaves root.
short_traceback ¶
A script's traceback with only the frames of files in the run directory (scripts/, lib/).
plain ¶
json.dumps default for tool results: small arrays as lists, numpy scalars, paths; anything else as repr.