Similarly, atoms can be thought of as a "spherical box", the boundary in this case is a full revolution around the potential well.
The thing is: Not everything is a box, hence the abstract model that uses photons as a shorthand for the behaviour of the EM field in a box isn't fully general, and simply doesn't apply outside of those scenarios.
That doesn't stop the vast majority of people talking about photons (and bosonic particles in general) as if they're individually countable things zipping around in free space.
Neutrons can be counted like this. Photons can't.