Contrary to popular belief, Marines aren’t really stationed at embassies or consulates to protect diplomats. They are there primarily to protect secret information—embassy buildings often process classified information, and many host CIA personnel as well. Marines are there to protect—and if necessary destroy—any classified information so it doesn’t fall into enemy hands. Foreign officers are told in their initial training not to think of the Marines as their personal bodyguards in case of an attack.
The Marine Corps itself makes this clear: “The primary mission of the Marine Security Guard (MSG) is to provide internal security at designated U.S. diplomatic and consular facilities in order to prevent the compromise of classified material vital to the national security of the United States.”
That said, the Marines can and do provide security in case the embassy is attacked and other security measures fail. “[T]he MSGs’ mission is to delay any hostile group long enough to destroy classified material and aid in safeguarding the lives of diplomatic personnel,” according to the State Department.