You can speculate that the sand plankton are photosynthetic organisms on which the sandworms feed for nourishment and energy, but this is never spelled out. However, an invasive ecology where all trophic levels are composed of different life stages of the same species is extremely unlikely to evolve....
As I understand it, the worms are supposed to be eating sand plankton and sandtrout.
The sandtrout at least I know are specifically named as the larval form of the sandworm, so it seems unlikely you could run a sustainable ecology on that kind of cannibalism.
As for the sand plankton, it's superficially plausible to point to blue whales as massive creatures which can sustain themselves on plankton, but the two problems there are (1) blue whales, at around 30m long, are a fraction the size of sandworms which have been reported up to 150m long ("specimens up to four hundred and fifty feet in the deep desert"), and (2) it takes
vastly more energy to move through sand than it does through water, barring some exotic kind of mass-disruption ability that Herbert never talked about.
If I were designing sandworms today I'd give them some kind of natural inbuilt organic nuclear reactor and have them feed off deposits of pitchblende in the planet's crust. (I always imagined Godzilla to run on the same kind of power.) EDIT: Alternately, you could postulate that maybe sandworms are far lighter and lower-mass for their size than one would expect -- maybe, like sharks, their skeletal structure is all cartilage with nanocomposite strength, and much of their internal size is nothing but air and gas bladders.