Skip to main content
POST /v1/agents/runtime/{runtime_id}/files/replace Replaces every occurrence of a pattern across the files selected by path and glob. Like Find Files, the rewrite runs natively in the guest agent: there is no sed, no shell and no command injection surface. Each file is rewritten atomically. The new contents are written to a sibling temporary file, flushed to disk, given the original mode, owner and group, and then renamed over the original. A reader either sees the whole old file or the whole new file, never a partial one, and a crash mid-run cannot leave a truncated source file behind.

Parameters

Response

Files with zero occurrences are not listed and are not rewritten, so their mtime is untouched.

Behaviour notes

  • Literal by default. Without regex, both the pattern and the replacement are treated as plain text: $1 in the replacement stays $1, and no escaping is required.
  • Capture groups need regex. With regex: true, $1, $2 and ${name} in the replacement expand to the corresponding capture groups.
  • Metadata is preserved. Mode bits, owner and group are restored on the rewritten file, so a replace across a tree does not silently change permissions or ownership.
  • Binary and oversized files are skipped, using the same rules as Find Files: NUL byte sniff, UTF-8 validation and an 8 MiB ceiling.
  • Directory symlinks are never followed, so a link cannot be used to rewrite files outside path.
  • Dry run first for wide patterns. dry_run gives you the exact per-file counts the real run would produce, without touching the filesystem.