MCPcopy Create free account
hub / github.com/anthropics/defending-code-reference-harness / exec_sh

Function exec_sh

harness/docker_ops.py:125–141  ·  view source on GitHub ↗

Run a shell command inside a container and return (rc, stdout, stderr). Unlike read_file/write_file this passes the command through sh -c so shell syntax (pipes, &&, redirects) works. Raises subprocess.TimeoutExpired on timeout — caller decides whether that's a tier failure or a hard er

(
    container: str, command: str, timeout: int | None = None
)

Source from the content-addressed store, hash-verified

123
124
125def exec_sh(
126 container: str, command: str, timeout: int | None = None
127) -> tuple[int, str, str]:
128 """Run a shell command inside a container and return (rc, stdout, stderr).
129
130 Unlike read_file/write_file this passes the command through sh -c so shell
131 syntax (pipes, &&, redirects) works. Raises subprocess.TimeoutExpired on
132 timeout — caller decides whether that's a tier failure or a hard error.
133 """
134 r = subprocess.run(
135 ["docker", "exec", container, "sh", "-c", command],
136 capture_output=True,
137 text=True,
138 errors="replace",
139 timeout=timeout,
140 )
141 return r.returncode, r.stdout, r.stderr
142
143
144def commit(container: str, tag: str) -> str:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected