They are Spaghetti Worms. The little ones, like yours, mostly live in the sand and the things you called legs are tentacles or filaments that come out of their mouth. Small things like bacteria and tiny copepods get 'stuck' on them and the worm then draws them into it's mouth. So they are beneficial filter feeders and good for your tank. I had some until I got a Wrasse who ate them all!
There are 2 bigger versions of Spaghetti Worms that we see in the Florida Keys. Rather than living in the sand, they make 'parchment' tubes and live under rocks. The smaller one has filaments that are white, roughly 8" to 12" long and about the size of string. The bigger one is often called a Medusa Worm. It's filaments are 15" to over 20" long and kind of a translucent blue/green in color and almost look like heavy monofiliment fishing line. The worm itself is 6" to 12" long and coils up like a spring when forced out of it's tube. The bigger ones are quite delicate and I've tried and failed twice to bring one of the big ones home for my old anemone tank. The second attempt survived about 6 weeks in my tank. After that I quit trying to collect them and just enjoy them in their native habitat in the Florida Keys.