When the President travels abroad, do he and his staff have to go through customs?

I’ve always been curious about this. When Air Force One lands, does the host country send customs inspectors and immigration agents on board to inspect their belongings and stamp their passports? Or do they just waive all this as a diplomatic courtesy?
How about when foreign heads of state visit the U.S., do they have to go through customs and have their passports stamped?

The President, and his entourage are in the country by negotiated agreement between both countries. Those traveling with the President, but not official members of the visiting head of state are merely tourists.

The extension of diplomatic immunity to visiting representatives of foreign governments is a fundamental aspect of international diplomacy. That includes armed guards, sealed luggage, and a great many other dispensations to the visitors. We do the same for visiting governments.

Not everyone in the rather large groups that travel with, and follow the President of the United States is exempt from search by customs. Those who are exempt must declare what they import, or export, but are not searched. The protocol office of the State Department oversee the process, and can bring charges if anyone acts in a way that would bring discredit upon the Office of the Presidency. They are restricted in their actions somewhat less that the customs office or police authorities.

You agree to suspend a few of your expectations to privacy before you ever get on Air Force One.

Tris

They are traveling as diplomats and so cannot be searched or detained.*

*Procedures for handling diplomats and diplomatic material are quite well-established and elaborate. You can x-ray a diplomatic container, but not open it. You may reject a shipment, but not part of a package and so on.

Foreign heads of state, and their retinues, are immune from the usual search procedures. The size of the retinue is a matter for agreement between the authorities of the visiting country and the host country.

A more interesting question would be whether the President’s retinue is subject to customs procedures on returning to the United States.