We develop a 2x2x2 general equilibrium model of trade with imperfect capital mobility, uncertain productivity in one sector, and risk-neutral producers chosing the capital allocation before uncertainty resolves. Without government intervention, the allocation of production is more export-oriented than what risk-averse consumers prefer. National welfare maximization hence justifies the use of trade policy. With uncertainty in both countries, a trade-off exists between trade as insurance against domestic shocks, and protection as insurance against foreign shocks. We find that the optimal trade policy depends not just on a country's comparative advantage, but also on the size and the correlation of the domestic and foreign shocks it experiences. Our results are consistent with persistent protection in sectors such as agriculture.