An airlock is used to release gases produced during fermentation while preventing oxygen and contaminants from entering the fermenter. It helps maintain a sterile and controlled environment for the yeast to do its job.