It's heated very hot and sealed sterile.
UHT stands for ultra-high temperature. The milk is heated to around 280°F (138°C) for just a few seconds, which kills nearly all bacteria and their spores. It's then packed into sterile, airtight cartons, usually lined with layers of foil and plastic that block light and air.
With nothing living left inside and no way for new microbes to get in, the milk can sit on a shelf for six months or more unopened. Regular pasteurized milk is heated less, to about 161°F (72°C) for 15 seconds, so some harmless bacteria survive and it has to stay cold.
UHT milk tastes slightly cooked or sweeter to some people because the high heat lightly caramelizes its sugars and changes some proteins. It's the standard way milk is sold in much of Europe.
Once opened, UHT milk needs refrigeration and should be used within about a week, just like fresh milk.