I have to concur with the above posts. Nailing boxes to wood studs is a standard trade practice. If it is dangerous then 99.9% of the homes in America are in big trouble. No codes violated here.