CO2 Sensor Sketch resets randomly

Which CO2 sensor? Post a link to the product page or data sheet.

If it has a heater, don't power it with the 5V output. The regulator may overheat and shut down, rebooting the Arduino.