Here's how to run the command with python and all the necessary escaping changes:
from subprocess import run
input_path = "some-input.jpg"
output_path = "some-output.jpg"
run([
"/opt/homebrew/bin/magick", input_path,
"-format", "roundrectangle 0,0 %[fx:w+1],%[fx:h+1] 10,10",
"-write", "info:tmp.mvg",
"-alpha", "set", "-bordercolor", "none", "-border", "1",
"(", "+clone", "-alpha", "transparent", "-background", "none",
"-fill", "white", "-stroke", "none", "-strokewidth", "0", "-draw", "@tmp.mvg", ")",
"-compose", "DstIn", "-composite",
"(", "+clone", "-alpha", "transparent", "-background", "none",
"-fill", "none", "-stroke", "#c7c7c7", "-strokewidth", "1", "-draw", "@tmp.mvg", ")",
"-compose", "Over", "-composite",
output_path])