There's no international "law" governing this, apart from the general rules like not causing a dangerous situation (so no buzzing the deck at 10ft for example).
That said, common courtesy comes into play, meaning that generally people tend to stay far enough away so as not to impede the operation of the other party.
Of course this might be interpreted differently and sometimes, deliberately or otherwise, aircraft and ships of different countries get too close for comfort for one of them.
Think the incidents where Russian naval air force bombers came close enough to US Navy ships in the Black Sea that their wake staggered people on the fantail of the ships who were filming them.
And yes, on occasion other countries do the same in seas they consider their backyard.