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

Function write_file

harness/docker_ops.py:97–108  ·  view source on GitHub ↗

Write bytes to a path inside a container. Uses ``docker exec`` (not ``docker cp``) so the write happens from the container's own view of the filesystem — under gVisor, ``/tmp`` is an in-sandbox tmpfs that host-side ``docker cp`` can't reach.

(container: str, path: str, content: bytes)

Source from the content-addressed store, hash-verified

95
96
97def write_file(container: str, path: str, content: bytes) -> None:
98 """Write bytes to a path inside a container.
99
100 Uses ``docker exec`` (not ``docker cp``) so the write happens from the
101 container's own view of the filesystem — under gVisor, ``/tmp`` is an
102 in-sandbox tmpfs that host-side ``docker cp`` can't reach."""
103 subprocess.run(
104 ["docker", "exec", "-i", container, "sh", "-c", 'cat > "$1"', "_", path],
105 input=content,
106 check=True,
107 capture_output=True,
108 )
109
110
111def rm(container: str) -> None:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected