Sensors in the brakes time each spin of each of the car's wheels. If you hit the brakes and a wheel slows down more quickly than it should, that's a sign your brakes are locking up and the sensors trigger the anti-lock brakes to start pumping to regain traction.
Other sensors will lay dormant for years, probably the entire life of your car, waiting for an impact that may never come. But if that impact ever does come, they'll trigger the airbags.
There are monitors watching your behavior as well. They watch how far and how hard you press the gas and how far you're turning the wheel.