I have about a 20 foot run for the outdoor compressor to my main breaker box. Can I use 8 gauge wire instead of 10 gauge? (because I already have this length and gauge.)
Yes, if it's approved for the line voltage and temperature and if connectors (e.g. wire nuts) are sized to fit. A lower gauge number means heavier wire, able to carry more current safely, with lower voltage drop for the same length, so it should be quite safe if fused correctly for 10-gauge.
The reason heavier wire than necessary is not used is to save on the cost of copper, and to avoid difficulty in routing and bending thick wire.