The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(code-execution): always send remote-write payloads as stdin_data
kshitijk4poor19cf343c74a1
diff --git a/tests/tools/test_code_execution_file_rpc.py b/tests/tools/test_code_execution_file_rpc.pyindex 6eea798fecc..88bc65eea24 100644--- a/tests/tools/test_code_execution_file_rpc.py+++ b/tests/tools/test_code_execution_file_rpc.py@@ -56,9 +56,9 @@ def test_generated_file_rpc_kwargs_correlation_and_authority(tmp_path, monkeypatmonkeypatch.setattr("model_tools.handle_function_call", dispatch)class Shell:- def execute(self, command, cwd=None, timeout=None):+ def execute(self, command, cwd=None, timeout=None, stdin_data=None):result = subprocess.run([shell, "-c", command], cwd=cwd, timeout=timeout,- env=dict(os.environ), stdin=subprocess.DEVNULL, capture_output=True, text=True)+ env=dict(os.environ), input=stdin_data or "", capture_output=True, text=True)assert result.returncode == 0, result.stderrreturn {"output": result.stdout}diff --git a/tests/tools/test_code_kernel_remote.py b/tests/tools/test_code_kernel_remote.pyindex 360ad28e6b0..27be21427df 100644--- a/tests/tools/test_code_kernel_remote.py+++ b/tests/tools/test_code_kernel_remote.py@@ -33,8 +33,6 @@ class ScriptedEnv:receives the command and returns the result dict."""- _stdin_mode = "pipe" # contract-faithful: ssh/docker/local deliver stdin-def __init__(self, handlers):self.handlers = handlersself.commands = []diff --git a/tools/code_execution_rpc.py b/tools/code_execution_rpc.pyindex 61c8918b160..46e777f3874 100644--- a/tools/code_execution_rpc.py+++ b/tools/code_execution_rpc.py@@ -40,34 +40,23 @@ def _private_dirs_cmd(mkdir_dirs, chmod_dirs) -> str:return f"umask 077 && mkdir -p {mkdir} && chmod 700 {chmod}"-def _remote_write_cmd(env, remote_path: str, content: str, *, atomic: bool = False) -> tuple:- """Build ``(command, stdin_data)`` writing *content* owner-only to *remote_path*.-- Payload transport follows the backend's stdin capability: ``pipe`` mode- (ssh, docker, local, singularity — the real shared-host backends) gets the- base64 via real stdin so the content never enters argv, where a co-tenant- can read it via ``/proc/*/cmdline`` for the command's lifetime.- ``heredoc``/``payload`` modes (modal, daytona, vercel, managed_modal —- isolated sandboxes where Modal-family stdin delivery is also unreliable)- keep the base64 echo form: the argv window there is one short write rather- than the whole run."""+def _remote_write(env, remote_path: str, content: str, *, atomic: bool = False,+ timeout: int = 30):+ """Write *content* owner-only to *remote_path*; returns the execute() result.++ The base64 payload always travels as ``stdin_data``: pipe-mode backends+ (ssh, docker, local, singularity: the real shared-host ones) deliver it on+ real stdin, so it never enters argv where a co-tenant can read it via+ ``/proc/*/cmdline``; ``BaseEnvironment.execute`` embeds it as a heredoc+ for heredoc-mode backends (modal, daytona, vercel), and managed_modal+ forwards it as ``stdinData``, the same contract ``_write_to_sandbox``+ relies on."""encoded = base64.b64encode(content.encode("utf-8")).decode("ascii")target = shlex.quote(remote_path)write = (f"base64 -d > {target}.tmp && mv -f {target}.tmp {target}"if atomic else f"base64 -d > {target}")- if getattr(env, "_stdin_mode", "pipe") == "pipe":- return f"umask 077 && {write}", encoded- return f"umask 077 && echo '{encoded}' | {write}", None---def _remote_write(env, remote_path: str, content: str, *, atomic: bool = False,- timeout: int = 30):- """Execute an owner-only remote write; returns the execute() result."""- cmd, stdin_data = _remote_write_cmd(env, remote_path, content, atomic=atomic)- kwargs = {"cwd": "/", "timeout": timeout}- if stdin_data is not None:- kwargs["stdin_data"] = stdin_data- return env.execute(cmd, **kwargs)+ return env.execute(f"umask 077 && {write}", cwd="/", timeout=timeout,+ stdin_data=encoded)def _rpc_token_ok(request: dict, rpc_token: str) -> bool:diff --git a/tools/code_execution_tool.py b/tools/code_execution_tool.pyindex 8d7121fc010..6a9470626ac 100644--- a/tools/code_execution_tool.py+++ b/tools/code_execution_tool.py@@ -453,9 +453,8 @@ def _get_or_create_env(task_id: str):def _ship_file_to_remote(env, remote_path: str, content: str) -> None:- """Write *content* owner-only to *remote_path*. stdin-capable backends carry- the payload on stdin so it never appears in remote argv; the rest get the- base64 echo form (see _remote_write_cmd). Raises on write failure: the+ """Write *content* owner-only to *remote_path*; the payload rides+ ``stdin_data``, never an ``echo`` argv (see _remote_write). Raises on write failure: thecaller ships secrets and code into dirs it believes are locked down, so asilent failure would run the next step against a missing or half-writtenfile."""