The legal action from two of Massachusetts’ poorest cities could offer a blueprint for other small sanctuary communities looking to push back on President Trump’s immigration agenda.