A system is provided for automatically shutting down an engine of a portable or handheld device in response to the engine operating while in an enclosed space, such as a garage, shed, room, etc. to prevent dangers associated with carbon monoxide accumulating in the enclosed space. The engine has an oxygen sensor in its exhaust that is configured to detect the presence or absence of oxygen in the exhaust. Fuel can be removed from the air/fuel mixture (e.g., less fuel being injected) based on the output of the oxygen sensor to maintain a given desired air/fuel ratio. If the amount of fuel provided continues to decrease over time in order to maintain the air/fuel ratio, the controller can assume the engine is operating in confined spaces and can shut down the engine.