these are called razor clams, they are mollusks like snails and slugs. they need moisture to survive. when you pour salt or saltwater on one it sucks the moisture out of the clam which causes it to try and escape out of the burrow, escaping from the irritant
These things are edible and tastes really good. They appear in small holes and you need to put in salt to lure them out so no need to worry on accidentally sitting on one of these😂. Also they appear in a specific kind of beach so don’t go around trying to look for small holes to pour salt into.