It does depend on the amount of oxygen and carbon dioxide. If you put a candle inside a tightly sealed jar it will only burn for a little while because combustion (burning) takes up oxygen hydrocarbons (something that contains hydrogens and carbons) and produces carbon dioxide and water vapour, surprisingly enough. The candle would eventually burn through the oxygen, create a lot of carbon dioxide and snuff itself out. Being in an open environment gives it plenty of oxygen. When we breathe at a candle it goes out because we breath IN oxygen and OUT carbon dioxide. The carbon dioxide puts the candle out!