SITL drone crash in VSCode but not from command line

If I run a gazebo simulation from within VSCode I end up getting the following warning immediately:

WARN [health_and_arming_checks] Preflight Fail: system power unavailable

Also after taking off I can get warnings such as the following:

WARN [health_and_arming_checks] Preflight Fail: Attitude failure (roll)
WARN [failsafe] Failsafe activated
WARN [failsafe] Failsafe activated
WARN [health_and_arming_checks] Compass needs calibration - Land now!
WARN [health_and_arming_checks] Preflight Fail: Compass 0 fault

In the simulator you can see that the drone loses control.

However, if the same experiment is repeated from the command line (rather than in VSCode), then the drone is stable and the warnings I mentioned do not appear. Why might this be?