Commit Graph

9 Commits

Author SHA1 Message Date
kshitijk4poor
1a748cc85a refactor(code-execution): one checked-execute helper, complete launch command
Gate follow-ups on the remote lockdown:
- _execute_checked(env, cmd, what, **kw) in code_execution_rpc replaces
  the three copy-pasted "execute, raise if returncode != 0" blocks
  (per-call setup, kernel dir setup, file ship via
  _remote_write(check=True)). env.execute always returns a dict, so the
  isinstance/(r or {}) guards go; the error carries command output only,
  never the payload.
- _ship_env_file_and_launch_prefix returned a half-built "( ... && "
  that both callers had to close; a caller that dropped the ")" or
  composed it differently would lose the load-bearing subshell. It now
  takes the launch command, builds the shared env map (RPC dir, token,
  PYTHONDONTWRITEBYTECODE, routed TZ) itself, and returns the complete
  command; the kernel passes only HERMES_KERNEL_DIR/PYTHONPATH, which
  drops its duplicated TZ block and lazy hermes_time import.
- _private_dirs_cmd(root, *subdirs): every caller spelled each path
  twice for mkdir and chmod.
- _run_remote_cell publishes the cell request with one atomic
  _remote_write instead of ship-to-.tmp then a separate unchecked mv,
  saving a backend round-trip per cell.
2026-09-27 00:56:31 +05:30
kshitijk4poor
19cf343c74 fix(code-execution): always send remote-write payloads as stdin_data
_remote_write branched on getattr(env, "_stdin_mode", "pipe") and only
passed stdin_data on pipe backends, echoing base64 into argv elsewhere.
BaseEnvironment.execute already embeds stdin_data as a heredoc for
heredoc-mode backends (modal/daytona/vercel), and managed_modal forwards
it as stdinData; _write_to_sandbox already relies on that for every
backend. The branch duplicated base-class logic, and its defensive
getattr default meant a fake env with neither _stdin_mode nor a
stdin_data parameter raised TypeError on every RPC response write. The
poll loop swallowed the error, so no res_* file appeared and
test_code_execution_file_rpc hung forever (it passes on base).

Collapse to one path that always passes stdin_data, and teach the
file-RPC Shell fake to accept it and feed it as input. ScriptedEnv no
longer needs its _stdin_mode stub.
2026-09-27 00:56:31 +05:30
beardthelion
5b8fd7fc32 fix(code-execution): lock down remote kernel/RPC dirs, keep RPC token out of argv
On shared remote backends the execute_code channel created kernel and
sandbox dirs under shared temp at the process umask (775 group-writable
under umask 002), wrote request/result files group-readable, and carried
HERMES_RPC_TOKEN on remote command lines where co-tenant users read argv
via ps for the whole run. A co-tenant could read tool arguments and
results, and on group-writable dirs forge RPC requests dispatched under
the user's approval context.

- All remote dirs are created owner-only (umask 077 + chmod 700, checked
  fail-closed) and every Hermes file write is mode 600.
- The token travels in a sourced env file inside a subshell so the vars
  never enter the backend's session-snapshot dump, and ships via stdin on
  pipe-capable backends so it never enters argv at all.
- The RPC poll loop rejects non-int seq requests before dispatch instead
  of replaying them every cycle.
- tool_result_storage gets the same owner-only treatment for archived
  tool output.

(cherry picked from commit aef21731d7fb8a4e0a6ada4ff9889264df4a8893)
2026-09-27 00:56:31 +05:30
Brooklyn Nicholson
ac2ffe60d0 test: cover persist_on_release in sandbox stub contracts and shutdown kill fakes
The four CI reds from #41225:
- persist_on_release is a background-only terminal modifier: join the
  sandbox blocked sets (precedent: heartbeat, 9acd0d33b6) in
  _TERMINAL_BLOCKED_PARAMS and the stub-drift tests' mirrors.
- The gateway shutdown sweep passes source="gateway_shutdown" so
  persisted jobs are still killed on host exit; the two shutdown tests'
  kill_all fakes now accept and assert that kwarg instead of raising
  TypeError that _quiet_step silently swallowed.
2026-09-25 13:49:31 -05:00
teknium1
9acd0d33b6 fix(code_execution): heartbeat is a background-only terminal modifier, blocked in the sandbox
The execute_code sandbox refuses background/notify modifiers on terminal(); heartbeat implies
notify and rides the same delivery path, so it joins the blocked set (and the stub-drift test's
mirror of it).
2026-09-21 15:02:49 -07:00
Teknium
cf8d53ba6b refactor(tools): simplify RPC token branch and kernel stderr/buffer loops 2026-09-02 23:08:22 -07:00
Teknium
02f92ec707 refactor(tools): unify remote result assembly, compact execute_code docs and comments 2026-09-02 22:33:03 -07:00
Teknium
89881ad022 refactor(tools): simplify execute_code stack — drop kernel_mode shim, extract per-call remote path, reuse terminal config helpers 2026-09-02 22:10:19 -07:00
Teknium
d4cec15b47 refactor(tools): first-wave simplification of tools/ (file ops split, lazy_deps, code_exec, approval, browser, delegate, mcp, skills, terminal, voice, media)
Behavior-neutral structural pass over tools/*: god-file extractions into
sibling modules (file_operations_common/lint/search, file_tools_paths/
read_tracking/write, code_execution_env/rpc, tool_search_catalog/names/
validation, tts_command_provider, ...), duplicate helper unification,
if/elif -> dispatch tables, dead-code removal, docstring compaction.
Tool schemas (get_tool_definitions) verified byte-identical to base.
2026-09-02 14:43:45 -07:00