Look up "right of innocent passage" to get an idea of what is nominally allowed regardnig international passage. Many countries will say that once you make fast via a mooring, anchor
or to a dock you have entered their country and thus need to go through customs and immigration (and perhaps health). If you just pass through a country's waters you will be within the law, but be prepared to be able to prove your intentions (passing through without landing) as well as your past travels. Note also that in order to clear into a country they will require your check-out papers from the last country, and you better be able to explain the times between. I met one person this summer in the Caribbean who believed (firmly, with much emotion) that he shouldn't need to check in anywhere because the $10 or $20 fee is unreasonable. Well, he's now no longer to enter territorial waters of 3 island countries (St. Maarten, St. Barts, Antigua) that I know of and I am sure that his name and boat are flagged for most of the other Caribbean islands so that when he does check in somewhere he is going to have issues.
That having been said, I have hoisted the Q-Flag and anchored overnight in St. Kitts and Nevis while traversing from Antigua to St. Martin and didn't check in; but I could have explained it as necessary (tired, bad weather) and made sure to not go ashore. But that is more of an exception than a rule.
I once sailed from Antigua (cleared out there) to Martinique but got a call there before I checked in and sailed back to Antigua and spent much of an afternoon explaining why my last checkout port was English Harbour and I was checking back into English Harbour 3 days later...
See Right of Innocent Passage