Pathogen drug resistance is a central problem in medicine and public health. It arises through somatic evolution, by mutation and selection among pathogen cells within a host. Here, we examine the hypothesis that evolution of drug resistance could be reduced by developing drugs that target the secreted metabolites produced by pathogen cells instead of directly targeting the cells themselves. Using an agent-based computational model of an evolving population of pathogen cells, we test this hypothesis and find support for it. We also use our model to explain this effect within the framework of standard evolutionary theory. We find that in our model, the drugs most robust against evolved drug resistance are those that target the most widely shared external products, or ‘public goods’, of pathogen cells. We also show that these drugs exert a weak selective pressure for resistance because they create only a weak correlation between drug resistance and cell fitness. The same principles apply to design of vaccines that are robust against vaccine escape. Because our theoretical results have crucial practical implications, they should be tested by empirical experiments.