It's just a type of ball sponge. Probably came in on the rock and is a filter feeder. Shouldn't hurt anything, but if you take it out try not to let air touch it. Air can often kill sponges. Looks like it's attached to the rock as well.
They can come from the sand but it's very unlikely. Sand doesn't really have a lot of hitchhikers if you buy it from the store. If it comes from someones tank it possible, but still much more likely to have come fro
The rocks.