They are safe and legal because they don't fire any kind of projectile. The firing mechanism is actually in reverse with the firing pin situated in the chamber. This of course prevents a live round from being chambered and only special plug fire cartridges can be loaded. These cartridges are loaded with a cap (slightly larger than your typical cap gun cap) and when detonated, a piston in the cartridge pushes against the firing pin in the chamber which then causes the slide or bolt to blow back. You get smoke, sparks, noise and a spent casing which creates a very realistic simulation of a real gun.
This makes them perfect for filming because you can fire them indoors and they're safer than traditional blank firers/starter pistols. You don't get an impressive muzzle flash like real guns loaded with blanks that are used in Hollywood but just do what I do and add the muzzle flash in your editing software.
So far, I've got this Browning 9mm pistol and an M16 assault rifle but I might get more in the future. They are expensive but if you're serious about making films then I suggest you invest in a few. I suggest buying from here as they stock many different models and they've got great customer service which is handy if you need repairs or spares.