How targeted isolation prevents contagion in an interconnected world