As an example, is the US President covered by diplomatic immunity when visiting an official summit in Brazil? Or could they in theory be arrested like any other foreigner?
It's not diplomatic but sovereign immunity that would be extended to heads of state in many cases. However the rules vary by country a fair bit. I only found a rather dated 1986 survey:
For a principle to be considered a rule of customary international law, it must be widely accepted by the international community and generally regarded as giving rise to legal obligations.
While a survey of the international community's approach to head of state immunity reveals wide agreement that heads of state are entitled to some immunity, there is no consensus on the extent of that immunity. For example, both the United Kingdom and Canada have enacted sovereign immunity statutes defining the head of state as the state.
French courts, in contrast, grant immunity to heads of state based on their status as government officials, an immunity similar to diplomatic immunity. Thus, the British grant a modified form of restrictive immunity based both on sovereign and diplomatic immunity, while the French seem to recognize greater degree of immunity like that accorded most diplomats.
There was also a para about the USSR and Eastern bloc countries that is irrelevant now. They subscribed to absolute immunity (somewhat unsurprisingly).
The ICC however did not exist until 1998/2002, so I would not be surprised if member states may have changed their laws at least in part as a result.
One 2020 (somewhat polemical) article notes that various [other] bodies have punted on the issue:
Does customary international law permit one State to arrest the sitting president of another State pursuant to a request by an international criminal court? The International Law Commission had around a decade to address the question while developing its draft articles on the immunity of State officials from foreign criminal jurisdiction. It didn’t. The question would have then been squarely presented to the Sixth Committee of the United Nations General Assembly for discussion by a wide and representative group of States. It wasn’t.
Did the United Nations Security Council resolution that referred the situation in Darfur to the ICC displace any immunities that Sudanese officials might otherwise enjoy? The Security Council had at least a decade to resolve the question. It didn’t.
Does the ICC Statute, which provides that immunities shall not bar the Court from exercising its jurisdiction, have the “horizontal” effect of displacing any immunities that might otherwise bar its member States from exercising their jurisdiction over persons in their territory? The Assembly of States Parties to the ICC Statute had at least a decade to resolve the question. It didn’t.
Instead, in May 2019, the Appeals Chamber of the ICC answered all three questions in the affirmative. [...]
Most of the State practice bearing directly on the question arose in the al-Bashir case itself. Fourteen ICC member States allowed Bashir to visit and declined to arrest him. Several asserted that doing so would violate customary international law. [...] More importantly, this practice was not representative. Indeed, the sample was skewed by al-Bashir and his government. Al-Bashir did not choose his travel destinations at random. His government contacted certain member States and obtained assurances from them in advance. The vast majority of member States—which his government did not contact, or which did not provide such assurances—were not given an opportunity to arrest him or refrain from doing so. To generalize from such selective practice would enable leaders accused of atrocity crimes to gerrymander customary international law in their favor.
Anyhow, the ICC also agreed that it's not diplomatic immunity that was the source of any putative immunity. Its
Appeals Chamber found that Head of State immunity derives from “the principle of par in parem non habet imperium, which is based on the sovereign equality of States.” However, international courts “do not act on behalf of a particular State or States. Rather, international courts act on behalf of the international community as a whole.” By implication, States that execute arrest warrants issued by international courts do not act on their own behalf, but instead on behalf of the international court and, ultimately, the international community as a whole.
So, essentially, the courted posited a supremacy of "the international community as a whole" as overriding inter pares sovereign immunity. The former is a somewhat new concept, as that article then discusses.
OTOH, going back as far as the Nuremberg tribunal, immunity for acts against international law (rather than that of country) was deemed inadmissible:
On the question of immunity, the position of the IMT consisted of the following:
The principle of International Law, which under certain circumstances protects the representatives of a State, cannot be applied to acts which are condemned as criminal by International Law. The authors of these acts cannot shelter themselves behind their official position in order to be freed from punishment in appropriate proceedings […]. On the other hand […] he who violates the laws of war cannot obtain immunity while acting in pursuance of the authority of the State if the State in authorizing action moves outside its competence under International Law (emphasis added).
So there's somewhat more precedent in claiming specific acts are not covered by head-of-state immunity anyhow.
There's also a 2002 ICJ case that noted the distinction between ordinary arrest warrants [i.e. by a national authority] and those by an international court
the ICJ considered that – despite the fact that heads of state, heads of government and foreign ministers enjoy “full immunity” from foreign jurisdiction and inviolability – they can be prosecuted before “certain international criminal courts”.
Here's that bit more detail (para 54):
The Court accordingly concludes that the functions of a Minister for Foreign Affairs (are such that, throughout the duration of his or her office, he or she when abroad enjoys full immunty from criminal jurisdiction and inviolability. That immunity and that inviolability protect the individual concerned against any act of authority of another State which would hinder him or her in the performance of his or her duties. [...]
The Court has also examined the rules concerning the immunity or criminal responsibility of persons having an official capacity contained in the legal instruments creating international criminal tribunals, and which are specifically applicable to the latter (see Charter of the International Military Tribunal of Nuremberg, Art. 7; Charter of the International Military Tribunal of Tokyo, Art. 6; Statute of the International Criminal Tribunal for the former Yugoslavia, Art. 7, para. Z; Statute of the International Criminal Tribunal for Rwanda, Art. 6, para. 2; Statute of the International Criminal Court, Art. 27). It finds that these rules likewise do not enable it to conclude that any such an exception exists in customary international law in regard to national courts.
So immunity from national warrants, according to the ICJ. Of course, state practice might actually differ, e.g. Noriega. That exception for international courts aside, the ICJ ruled an almost King/Soviet-level amount of immunity, extending to past acts before taking office!
In this respect, no distinction can be drawn between acts performed by a Minister for Foreign Affairs in an "official" capacity, and those claimed to have been performed in a "private capacity", or, for that matter, between acts performed before the person concerned assumed office as Minister for Foreign Affairs and acts committed during the period of office. Thus, if a Minister for Foreign Affairs is arrested in another State on a criminal charge, he or she is clearly thereby prevented from exercising the functions of his or her office. The consequences of such impediment to the exercise of those official functions are equally serious, regardless of whether the Minister for Foreign Affairs was, at the time of arrest, present in the territory of the arresting State on an "official" visit or a "private" visit, regardless of whether the arrest relates to acts allegedly performed before the person became: the Minister for Foreign Affairs or to acts performed while in office, and regardless of whether the arrest relates to alleged acts performed in an "official" capacity or a "private" capacity. Furthermore, even the mere risk that, by travelling to or transiting another State a Minister for Foreign Affairs might be exposing himself or herself to legal proceedings could deter the Minister from travelling internationally when required to do so for the purposes of the performance of his or her official functions.
In this regard the ICJ Arrest Warrant goes far beyond the US FSIA, which codified the Tate Letter, in covering only official acts. (The President of the ICJ then happened to be a French jurist, Gilbert Guillaume, but I have no idea if French national law treatment of the matter influenced him. He clearly didn't dig universal jurisdiction though, declaring that it would be "a step backward".)
The Vienna Convention applies immunity only to the Head of a mission, and their diplomatic staff.
In the situation that a Head of State was accused of a criminal act committed in the country he/she was visiting, there would be no automatic immunity required by the Vienna Convention. Nevertheless, it would be surprising if the host country enforced its criminal law in this most unusual situation.
In the situation in which there was an outstanding arrest warrant for the Head of State, it would be expected that the host country would have made it clear to the visiting Head of State that this would be executed if they enter. This could apply also to ICC warrants.
Most countries have some kind of diplomatic visa that the President would receive. On the other hand, when the King or Queen of the UK travels, they don't present a passport (although their visit is probably logged as a diplomatic visa entry - the rules are different and not transparent for Kings). This is actually irrelevant. Immunity is not tied to some visa status.
So the US President would know in advance that he/she would, or would not be arrested, and decide to go to Brasil accordingly.
The principle of International Law, which under certain circumstances protects the representatives of a State, cannot be applied to acts which are condemned as criminal by International Law (source).
In 2019 ICC has judged that heads of state have no immunity from criminal prosecution by the international criminal courts. German Justice Minister Marco Buschmann also confirmed that if V. Putin (head of state at the time) enters the territory of Germany, then he will be arrested. Also, on PBS.org:
in this case, Mr. Putin would not have the defense of head of state immunity, because it's an international criminal tribunal. It's not a Ukrainian court. It's an international court, and that defense is not of effect before the International Criminal Court.