A fruit fly trap works by attracting flies into a container with bait (like apple cider vinegar), where they become trapped and drown. The container is usually designed with a narrow opening that makes it difficult for the flies to escape.