This is how you can preserve food. Answered
Echoing what the others say, it's all about "available water".
Salt and sugar does the same thing - draw water away, or make the water too salty/sugary for bacteria to live in it.
Things that change the acidity kind of does the same thing - they make the water inhospitable, so the bacteria can't live in it.
You can also make a mix of the two, using a bit of vinegar and a bit of sugar.
Drying something also takes away the water.
This is what is done with jellies and jam and fruit preserve and a lot of other things - olives too.
The only thing that's different from all of these only works on things that are sterile - you can cover the outside in something that's toxic.
The toxic thing can be a mold, strangely enough - because the mold makes toxins to protect itself, so other bacteria and molds can't survive. But it means you have to cut the outside away when you want to use it, and then you can't leave it, because you've opened a door for bacteria and different molds to "enter".
Camembert is like this - the outer layer is a living mold that kills everything else.
The toxic thing can also be residue from smoke because the thin outer layer is toxic, the bacteria can't enter. We can take a big bite of it, though, because the layer is very thin, so there's not enough toxin to affect us.
bacon and fish are often preserved like this