They come in on everything from LR to corals to Chaeto. They move towards the light and will usually cover corals and the glass. The can be siphon out and some fish will eat them but when they get out of hand you usually need to use a combination of siphoning and chemicals. Clear or lite green ones are harmless but red ones aren't and need to be removed before they die off and cause a problem, as when they die they release poison into the tank.
Polyclad Flatworms Not Reef Safe
This is a very large flatworm that feeds on snails and sometimes mollusks. It can be in the tank for months without anyone knowing that's there until it comes out in the open. Once it's out in the open it's pretty easy to remove.
Red Planaria Red Planaria flatworms can grow to plague like levels in an aquarium and will release toxins when they die. They also cover corals and can cause them to die from lack of light, so they need to be removed.
Natural Method or Removal
You can eliminate Flatworms by using certain fish, like Sixline Wrasse and some Hogfish, like the Candy Hog, Leopard Wrasse and a number of the Halichoeres species H. melanuras . Mandarin will sometimes eat them too but it's not a sure thing. The Blue Velvet Nudibranch (Chelidonura varians) will also eat them but they don't have a long live span and usually will die once they're all gone. You can also siphon them out of the tank, this does take time and you need to wait for the lights to be on, as they're attacked to the light.
Salifert’s Flatworm Exit works well but you usually need to do a second treatment to get rid of them. You also need to be prepared to siphon out all the dead Flatworms and then do a large water change after each treatments, as when the Flatworms die they release posion, which can kill things in the tank.