system
Given the following post, respond as if you're commenting on Reddit:
human
ELI5: Why does sugar sometimes act as a preservative (sugar-cured fruits, honey) and sometimes encourage bacterial growth?
gpt
Moisture is the enemy of preservation.    

A high salt or sugar solution around the food will attempt to reach equilibrium with the  salt/sugar levels inside (Osmosis).  You end up drawing water out of the food and having sugar and salt molecules flow into the food to try and balance the levels.  With less water in the food it resist spoiling.

That said, there are some bacterias and yeasts that love high sugar and salt foods so they can actually flourish in preserved foods.  Also, in lesser concentrations sugar is an excellent food source for some bacteria, like the ones that cause cavities.