It could leave your body on its own. But if your doctor finds it, they can prescribe a medicine like praziquantel or nitazoxanide. These will either kill the adult worms or cause you to poop them out. But they won't kill the eggs, which can still cause infections.
Will pinworm medicine kill other worms?
Mebendazole kills worms that cause gut infections such as threadworm (sometimes known as pinworm) and other less common worm infections (whipworm, roundworm and hookworm).
Can Reeses pinworm medicine kill tapeworms?
This product works but it does not kill the worms, it paralyses them so that you are able to expel them and that takes 2-3 days.