The treatment of viral infections using antiviral drugs has had a significant public health benefit in the setting of human immunodeficiency virus (HIV) infection, and newly developed drugs offer potential benefits in the management of other viral infections, including acute self–limiting infections such as influenza and picornaviruses (including the rhinoviruses that are responsible for a large proportion of ‘common colds’). A serious concern with such treatments is that they may lead to the selection of drug–resistant strains. This has been a significant problem in the case of HIV infection. Existing mathematical–modelling studies of drug resistance have focused on the interactions between virus, target cells and infected cells, ignoring the impact of immune responses. Here, we present a model that explores the role of immune responses in the rise of drug–resistant mutants in vivo. We find that drug resistance is unlikely to be a problem if immune responses are maintained above a threshold level during therapy. Alternatively, if immune responses decline at a fast rate and fall below a threshold level during treatment (indicating impaired immunity), the rise of drug–resistant mutants is more likely. This indicates an important difference between HIV, which impairs immunity and for which immune responses have been observed to vanish during treatment, and viral infections such as influenza and rhinoviruses, for which such immune impairment is not present. Drug resistance is much more likely to be a problem in HIV than in acute and self–limiting infections.