In cloud computing, the task replication with cancellation (TRC) approach aims to reduce the expected task completion time while mitigating additional load and user expenses. However, its effectiveness may be hindered by co-residence attacks, where attackers may access users’ data through co-residing their virtual machines (VMs) with users’ VMs on the same server. Particularly, creating more task replicas has two-fold effects: a task has larger chances to complete in a shorter time but becomes more vulnerable to co-residence attacks (incurring higher data theft probability). The objective of this paper is to formulate and solve an optimization problem (a minmax game problem) that finds the optimal number of task replicas balancing the two conflicting effects. Resulting solutions to the proposed optimization problem can maximize the user's utility while considering the strategic attack behavior of maximizing the attacker's utility. The solution methodology encompasses a new probabilistic model of evaluating the user's and attacker's utilities. As demonstrated through examples, there exist complicated interactions of different model parameters impacting the utilities of users and attackers and thus the optimization solutions, justifying necessity and significance of the suggested model and methodology.