They're called "Squibs", and they're just tiny explosive packets, kind of like really small firecrackers. They are detonated remotely, and there's very little chance of injury unless an actor falls and one explodes right near his eye.
Steven Spielberg, as a very young filmmaker, would use tiny wooden fulcrums with dirt planted on them, so that when you stepped on the side that was up, it would "see-saw" the dirt into the air. He used this technique because he was too young to get fireworks. It's pretty effective if you're trying to show someone running and bullets hitting the ground next to their feet, and have a budget of, say, $0.