My understanding is that the benefit of being outdoors is the ability and opportunity to regularly focus on things at a distance that helps, so sunglasses wouldn't factor in.
It’s also exposure to natural light. Myopia jumps when kids are exposed to artificial lighting [1]. It seems some constant is hard coded into our genes to calibrate our eyes to the Sun’s light. (Artificial natural light, despite sounding like an oxymoron, can help.)
That was the leading theory for many years that explained why adult humans today have much worse vision that humans of the not-so-distant past, but it was disproven in the last decade.
We don't yet understand why, but lack of exposure to sunlight is what causes still-developing eyes to grow incorrectly.