This paper proposes a theory of foreign reserves as macroprudential policy. We study an open-economy model of financial crises in which pecuniary externalities lead to overborrowing, and show that by accumulating international reserves, the government can achieve the constrained-efficient allocation. The optimal reserve accumulation policy leans against the wind and significantly reduces the exposure to financial crises. The theory is consistent with the joint dynamics of private and official capital flows, both over time and in the cross-section, and can quantitatively account for the recent upward trend in international reserves.