Formulation is one aspect – keep pH as low as you can to help reduce microbial growth. Addition of preservatives is often done, and it is not a complete solution. Calcium propionate can be helpful – speak with the supplier for best recommendations. Achieving lowest possible water activity is also key. Most consider below 0.65 Aw to be to objective. This will mean utilizing other humectants that help provide mouthfeel. Corn syrups, glucose, glycerin, for humectancy, as well as high fat content for mouthfeel texture.
Above all will be meticulous cleanliness at all stages and especially anywhere there is physical contact of any kind with the baked product. Testing protocol for microbes in the baked product is important too.