Pickles and hot peppers are typically sold in glass jars because the pickling process used to produce pickles requires high temperatures and tight seals, properties both achieved with glass jars. Pickling is the process of immersing a vegetable in a brine until it is no longer vulnerable to spoilage.
When cucumbers are pickled by lacto-fermentation in saltwater brine, lactic microbial organisms turn sugars in food into lactic acid. The environment surrounding the cucumber inside of the glass jar turns acidic. Spoiling bacteria cannot multiply inside of this acidic environment.
Pickling can be applied to other vegetables beyond cucumbers and hot peppers such as onions, green beans and cauliflower. Fruits such as strawberries and lemons can also be preserved through pickling.