We use a conventional dynamic economic model to integrate individual optimization, equilibrium interactions, and policy analysis into the canonical epidemiological model. Our tractable framework allows us to represent both equilibrium and optimal allocations as a set of differential equations that can jointly be solved with the epidemiological model in a unified fashion. Quantitatively, the laissez-faire equilibrium accounts for the decline in social activity we measure in US micro-data from SafeGraph. Relative to that, we highlight three key features of the optimal policy: it imposes immediate, discontinuous social distancing; it keeps social distancing in place for a long time or until treatment is found; and it is never extremely restrictive, keeping the effective reproduction number mildly above the share of the population susceptible to the disease.