We introduce external risks, in the form of shocks to the level and volatility of world interest rates, into a small open economy model subject to the risk of sudden stops—large recessions together with abrupt reversals in capital inflows| and characterize optimal macroprudential policy in response to these shocks. In the model, collateral constraints create a pecuniary externality that leads to "overborrowing" and sudden stops that arise when the constraints bind. The typical sudden stop generated by the model replicates existing empirical evidence for emerging market economies: Low and stable external interest rates reinforce "overborrowing" and lead to greater exposure to crises typically accompanied by abrupt increases in interest rates and a persistent rise in their volatility. We solve for the optimal policy and argue that the size of a tax on international borrowing that implements the policy depends on two factors, the incidence and the severity of potential future crises. We show quantitatively that these taxes respond to both the level and volatility of interest rates even though optimal decisions in the competitive equilibrium do not respond substantially to changes in volatility, and that the size of the optimal tax is non-monotonic with respect to external shocks.