This is something we have no information about, as it's solely server-sided.
Do you have any theories on how either of what you just mentioned would work? And is there any way to confirm those theories?
I have theories of my own, but I have no means to confirm any of it.
---
Edit: Looked closer into these, and found some new info.
(Credits to Cjay for insight on the swimming part)
I believe swimming is done with just the floor flag inversed(the flag that's set in map loading,
outside of object spawning(since water isn't an object!). Looked into it in OSRS and any ducks and other similar creatures which spawn on water, could never leave water. In Lumbridge, there is a farm in which there are also ducks on the main land, however those ducks have a different npc id, and can never enter the water. They also have a custom script where they flee from any player that walks near them.
As for the implings and other flying creatures, I believe it would be done through projectile checks. There
is a scenario in Wintertodt, where the walls aren't projectile clipped, thus allowing creatures such as implings to wander inside, however I believe there's a further check down the line that checks for certain area controllers which prohibit unwanted creatures from entering said area.