Tumours display an astonishing variation in the spatial distribution, composition and activation state of immune cells, which impacts their progression and response to immunotherapy. Shedding light on the mechanisms that govern the diversity and function of immune cells in the tumour microenvironment will pave the way for the development of more tailored immunomodulatory strategies for the benefit of patients with cancer. Cancer cells, by virtue of their paracrine and juxtacrine communication mechanisms, are key contributors to intertumour heterogeneity in immune contextures. In this Review, we discuss how cancer cell-intrinsic features, including (epi)genetic aberrations, signalling pathway deregulation and altered metabolism, play a key role in orchestrating the composition and functional state of the immune landscape, and influence the therapeutic benefit of immunomodulatory strategies. Moreover, we highlight how targeting cancer cell-intrinsic parameters or their downstream immunoregulatory pathways is a viable strategy to manipulate the tumour immune milieu in favour of antitumour immunity.