Imagine a simple world with two countries (1 and 2) and two commodities (A and B). It might be that country 1 has something that allows them to produce both A and B with greater efficiency than can 2. But even when that's the case, they (and the whole world) do better when they continue to concentrate on producing the one for which they have the greatest advantage (say, A). Even if 1 can also produce B more efficiently than can 2, it works out better if they ignore that, leaving it to 2, and just concentrate on producing all the A they can.
That solution doesn't change if there are more countries and more commodities. It might make the big picture more complicated, but it remains a better solution for both 2 and for the entire world if 2 concentrates on producing whatever it's best at.
(Note that this is purely based on economics of commodities, and not national security. When some of those commodities are things like "missiles", it may well be that a country things they need to have a guaranteed secure supply, should one of their trading partners decide not to be friends anymore.)