In simple terms, they cannot, without major redesigns to the structure of large container ships, and possibly containers themselves.
Companies are very reticent. Accurate figures for exactly how many of the millions of containers shipped each year are actually lost overboard are very hard to find. Probably significantly less than 1%. But, that is still quite a large number of individual containers. Eventually, containers WILL sink, but may remain afloat for a significant period.
Probably steps could be taken, but these would involve significant cost, and may impact on the economic operating model, and reduce profitability. The total number of containers carried per ship /trip may reduce, while operating costs remain effectively unaltered.
Sadly, it is easier [and cheaper ] to simply allow the insurance companies to reimburse the customers who entrusted containers to them and face slightly increased premiums.
Looking at the photo above, there is nothing that can practically be done to stabilize that load while at sea. Even in port, it will be a delicate operation to recover them. Normal port loading systems are not designed to deal with containers on their side, or upside down.