Locate two adjacent studs on the wall. Tap the wall gently with a hammer to locate the studs. The hammer makes a solid sound over the stud but sounds hollow where there is no stud. Studs typically set 16 to 24 inches apart. Mark the stud location on the wall once you locate them.
Draw the shelf opening onto the wall between the two studs, using a straight edge and a carpenter's level to ensure the sides are straight. Draw the opening so it is at least 4 inches taller than the height of the cable box.
Cut out the opening along your marked lines with a drywall jab saw. Begin by cutting along the top line until you reach the stud. Cut through the drywall flush to the stud until you reach the bottom line. Cut along the bottom line until you reach the other stud, cut up along the stud, and pop out the drywall.
Measure the depth of the opening. Most walls are made from 2-by-3 or 2-by-4-inch studs, so they have a 3- or 4-inch depth. Measure the distance between the two studs along the top cut. Transfer this measurement to a 2-by-4-inch or a 2-by-3-inch board, using the board size that matches your wall depth.
Drill two holes in each end of the board. Place the holes 1-inch in from the edge and drill them at a 45-degree angle, using a bit one size smaller than the wood screws. Place a countersink bit on the drill, adjusted to match your screw size and widen the top of each hole with the bit.
Place the board at the top of the wall opening with the top of the drilled holes facing down. Screw the board into the wall studs using wood screws. Tighten the screws so the heads are sunk into the countersink holes.
Cut a 2-by-6 or 2-by-8-inch board to fit between the walls studs. The width of the board determines the depth of your shelf. Drill and countersink the screw holes in this board as you did the top board. Screw the board to the studs to form the shelf and the bottom of the opening.
Cover any gaps between the wood and surrounding drywall with drywall tape. Cover the tape, exposed wood and the back wall of the shelf with a thin coat of drywall mud, using a drywall knife to smooth it on.
Paint the interior of the shelf with a primer once the mud dries. Paint over the primer with a paint that matches the surrounding wall color. Allow the paint to dry for 24 hours before placing your cable box on the shelf.