I can imagine a futuristic Tree like structure with Megapacks affixed in the air. In case of fire faulty module is ejected, falls to the ground and slids away to a designated disposal bay. Or just build on a slight incline with all modules on tracks.
Megapack is a relatively new thing. Earlier Tesla utility-scale batteries including the one in South Australia were made of smaller modules called Powerpack (I don't remember their size). A Powerpack catching on fire will presumably release fewer toxins and stuff than a Megapack, simply through being smaller.
It looks like some effort went into stopping the fire in the burning Megapack from spreading into other modules. So the modularity doesn't automatically contain the fire all by itself, but it apparently helps.
More coverage from a Tesla battery stan:
https://reneweconomy.com.au/tesla-megapack-container-on-fire...