This question already has an answer here:
I'm designing a custom headboard for our bed and I want to install electrical into the cubbies I am making in the headboard (primarily for cell phone charging). In my current design, the electrical box would be installed into a cut out 2x4.
I've attached two sketchup models for reference. My primary question is this: Are there any U.S. electrical codes or even best practices I need to be aware of in regards to where and into what material I can install an electrical box? The only thing I could find was that a box can protrude through up to 1/2" of drywall, so I'm wondering if that means that attempting to protrude through a larger (flammable) piece of material like this is against code. If you have any other related advice/caution about running electrical into furniture, that would be welcomed as well. Thanks!
EDIT: In my design, this 2x4 could be changed to a different material, but initially I was trying to keep the structure to 2x4s and plywood for simplicity. I could switch to a thinner material if that would help me to be in compliance.