Mountain biking through sand, for the most part, sucks. But if you’ve got no choice keep this in mind: spinning = good, mashing = bad.
Yes I am a masher but when it comes time to riding through a sandy area, I mentally remind myself to spin at a higher cadence. Spinning at a higher cadence provides a steady power transfer to the rear wheel which will help move you through the sand better than mashing. When you mash, the power transfer to the rear wheel comes in spurts. The gaps between the spurts of power will immediately stop your forward momentum as the sand grabs onto the wheels. When enough of these build up, it becomes extremely difficult to continue riding through the sand.
So when you come onto a sand area: drop a few gears, sit in your saddle and spin away through the sand section. The goal is to maintain your constant forward progress because once the bike stops trying to restart in the sand is a very difficult task.