Technological change, from the advent of robots to expanded trade opportunities, creates winners and losers. How should government policy respond? We provide a general theory of optimal technology regulation in a second–best world, with rich heterogeneity across households, linear taxes on the subset of firms affected by technological change, and a nonlinear tax on labor income. Our first set of results consists of optimal tax formulas, with minimal structural assumptions, involving sufficient statistics that can be implemented using evidence on the distributional impact of new technologies, such as robots and trade. Our final results are comparative static exercises illustrating, among other things, that while distributional concerns create a rationale for non-zero taxes on robots and trade, the magnitude of these taxes may decrease as the process of automation and globalization deepens and inequality increases.