The Sun is the ultimate source of energy for almost all food chains. Plants capture sunlight through photosynthesis and convert it into glucose. When herbivores eat plants, they obtain that stored energy. Carnivores then get energy by eating herbivores, and so on up the chain.
Some energy is lost as heat at each level, but enough is transferred to support the organisms in the ecosystem. The Sun also powers decomposers like bacteria and fungi, which recycle nutrients.