Can you run cable next to an attic access opening?
Yes, but the cable has to be protected. Section 334.23 sends you to 320.23 for the actual rule, and 320.23 splits the answer based on how the attic is reached.
The two cases in 320.23
Section 320.23(A) covers cable run across the top of floor joists, or within 2.1 m, or 7 feet, of the floor or floor joists across the face of rafters or studding, in an attic or roof space that is accessible. In those locations the cable must be protected by substantial guard strips at least as high as the cable.
Then comes the part that answers the attic hatch question. Where the attic space is not accessible by permanent stairs or a permanent ladder, protection is required only within 1.8 m, or 6 feet, of the nearest edge of the scuttle hole or attic entrance. Outside that 6 foot radius, cable lying across the top of the joists needs no guard strips, because nobody is walking out there.
If the attic does have permanent stairs or a fixed ladder, that relief disappears. Every cable crossing the top of the joists anywhere in the space needs guard strips, because the code now treats the whole attic as walkable storage.
What counts as protection
A guard strip is a piece of lumber, commonly a 1x2 or 2x2, run on each side of the cable and at least as tall as the cable so a boot or a stored box lands on the wood instead of the jacket. Running the cable through bored holes in the joists satisfies the intent as well, and 300.4(A)(1) then requires the hole to be at least 32 mm, or 1 1/4 inches, from the nearest edge of the framing member, or a 1.6 mm, or 1/16 inch, steel plate over the face.
Section 320.23(B) is the relief most people forget. Where cable is run along the side of rafters, studs, or floor joists, meaning stapled to the face rather than laid over the top, neither guard strips nor running boards are required. Turning the cable 90 degrees and stapling it to the side of the joist is often faster than building a lumber channel.
Do not forget the box and the fixture
Section 314.29 requires boxes and conduit bodies to be installed so the wiring inside is accessible without removing any part of the building. A junction box buried under blown insulation in a knee wall is a violation even if the splices are perfect. Mark it or keep it visible.
Also watch temperature. Section 310.15(B) and Table 310.15(B)(1) require ambient correction, and a sealed attic in July can sit at 55 degrees C. Table 310.15(B)(1)(1) gives a 0.76 factor at 51 to 55 degrees C for 90 degrees C insulation, and 334.80 caps NM-B at the 60 degrees C column for final ampacity anyway.
Field takeaway
Scuttle hole with no permanent ladder means guard strips only within 6 feet of the opening. Pull-down stairs or a fixed ladder means guard strips everywhere the cable crosses the top of the joists. Stapling to the side of the framing avoids the whole issue, and keeping boxes above the insulation line keeps 314.29 happy.