What is the origin of individual differences in ideology and personality? According to the parasite stress hypothesis, the structure of a society and the values of individuals within it are both influenced by the prevalence of infectious disease within the society's geographical region. High levels of infection threat are associated with more ethnocentric and collectivist social structures and greater adherence to social norms, as well as with socially conservative political ideology and less open but more conscientious personalities. Here we use an agent‐based model to explore a specific opportunities‐parasites trade‐off (OPTO) hypothesis, according to which utility‐maximizing agents place themselves at an optimal point on a trade‐off between (a) the gains that may be achieved through accessing the resources of geographically or socially distant out‐group members through openness to out‐group interaction, and (b) the losses arising due to consequently increased risks of exotic infection to which immunity has not been developed. We examine the evolution of cooperation and the formation of social groups within social networks, and we show that the groups that spontaneously form exhibit greater local rather than global cooperative networks when levels of infection are high. It is suggested that the OPTO model offers a first step toward understanding the specific mechanisms through which environmental conditions may influence cognition, ideology, personality, and social organization.