Companions' AI is really dumb - throughout the game they've died from stepping into hazardous surfaces much more often than from combat situations. It seems they try to follow a formation on higher priority than properly avoid those surfaces. It gets especially annoying if they get killed by lava surface, which you can't douse with water, and that leads to ressurect scroll waste and ressurected companion consecutive instakill.
So first suggestion is this:
-Ressurect companions on the nearest non-hazardous surface, or near ressurecter, because otherwise they get insta-killed again.
And secondly, if there is no way to improve AI to avoid hazards then the next suggestion is this:
-In formation menu create one more formation - "Follow the exact steps of the controlled character". It was done even back in BG series, if you remember, for exactly these types of situations where you had to avoid hazardous surfaces.
The icon for this formation is the one on the left: