Running 40ft of wire to garage, buriable
Put a sub-panel in the garage, not a junction box. If you join 12/2 wires to the circuit, you CANNOT have more than a 20 amp breaker feeding them. If you put in a sub-panel with breakers, the 20 amp limit comes into play after the sub--panel breakers, and the feed from the main is sized for the wires feeding the sub-panel. Go bigger than you think you'll need, you won't regret it later, as most people that put in a tiny one eventually do. The sub-panel can be a "main" type panel (and could be 100 Amps, even if only fed with 30, 40, or 50 Amps), you just need to remove the ground to neutral bond. 10/3 (which has 4 wires, including the ground) would be adequate IF you are only looking for 30 amps capacity. But you actually should get individual wires and...

Put conduit in the ground, not direct burial cable. Trenches are expensive (in money or labor) conduit is cheap (in less wire damage, and the ability to replace wires later without digging again.) You need 4 wires (hot, hot, neutral and ground) and you should really consider all future uses when choosing the size of wire, rather than picking the smallest possible size. Doing it once is cheaper than doing it over.

You need to define your loads - compressors come in many sizes. The plate on the motor should give amps as well as volts; though starting them is often a bit more demanding than the running rating those provide (sometimes there is additional data on the plate which may help with starting load or required breaker size, sometimes not.) If we go minimal and assume your lighting circuit is 15 Amps at 120VAC and your tool circuit is 20 Amps at 120VAC, you're riding the hairy edge if your compressor needs more than a 10 Amp at 240VAC breaker with a 30 Amp feed, and it kicks on while your 120 tools are going. Might want to go to #8 copper or #6 aluminum for your conductors and kick up to 40Amps - default recommendation around here is actually 50A for a typical garage shop. At least choose conduit big enough to allow for that later...