How do I keep water from getting in and out of a dishwasher drain air gap?
Dishwasher drain airgap.

It's placed above maximum sink full water level to prevent siphoning grey-water from the sink into the dishwasher if the P-trap ever gets plugged and you try to empty a full sink.

If water is spewing or leaking from the overflow slots in the cover, either the outflow from the airgap into the sink drain has become clogged (especially if it is set up to discharge into the waste disposal unit, food crud buildup, bioslime growth) or the unit is defective and needs to be replaced.

Diagram on how the drain airgap functions.