In plumbing, a trap is a U-shaped section of pipe designed to trap a liquid or gas to prevent unwanted flow. It also prevents insects, worms, cockroaches, and mice from entering the house.