The
Mavic 2 is rated to 5000m above sea level, so 4000m should be perfectly OK. People have apparently gone a good deal higher than that (almost certainly not legally), and although it's not entirely clear how modified those drones were it's very likely that the 5000m is just what DJI considers "safe" rather than an enforced ceiling and the drone would be able to operate higher if pushed and conditions were good.
Air pressure (and hence temperature) drops with altitude, so you'll have colder batteries and the thinner air means that the motors will have to work harder to keep the drone in the air. You'll also typically get higher windspeeds than at sea level, which will again reduce battery life, so expect flight times to be further reduced accordingly.
Check the wind conditions with something like UAV Forecast before you fly, keep an eye on the battery life indicator, make sure you have plenty of battery to RTH, and you should be fine.