Yes you can but there are a couple of things to consider first. The first thing is to find out if it's legal to take in your area and if so, what the limit is. I know in Florida you can take a one gallon bucket per person, per day.
The next thing is where to take it from. It's not a good idea to take the sand from the beach itself, or from the shoreline. Either one can have contaminates like cigarette ashes, lotion, etc. from the beach and the shoreline will have critters in it that require extremely high oxygen levels that will die in your tank. Better to take sand from under the water offshore a ways. You also need to be aware of other problems. Never collect near any kind of drainage ditch, sewer, or even a river. Stay well away from areas that have high boat traffic like piers, docks, etc....also beaches that are used heavily by people. Even following these precautions, you should let the sand sit in some saltwater before using and if you notice any kind of oil slick on the surface of the water, don't use the sand!
To me (at least), I'd rather buy a bag of playsand from Home Depot rather than take the chance of putting something unwanted in my tank.