I'd like to add another light switch in my bathroom, near the doorway. There is a narrow area between the door frame and a wall cabinet, but there are studs behind this area, so no room for an electrical box. Below the cabinet is a granite backsplash, which I don't want to cut through. I'm thinking of putting the switch into the side of the cabinet. Would this violate any codes? The box would be inside the cabinet, but I'd put wood around it so that it's not visible or touchable. Any problem doing it this way? Thanks for any help.
A box in the cabinet should be fine. You need to protect the romex going into the box somehow if people will be jamming stuff in the cabinet. A piece of Liquidtight flexible metal conduit or EMT would work, or you can just put wood around the wire as well.
The box doesn't really need wood covering it on the inside.
BTW- if you use metal conduit, use a metal box and don't forget to ground the box.