Successful avoidance of recurrent threats depends on inferring threatening agents’ preferences and predicting their movement patterns accordingly. However, it remains largely unknown how the human brain achieves this, despite the fact that many natural threats are posed by complex, dynamic agents that act according to their own goals. Here, we propose that humans exploit an interactive cognitive map of the social environment to infer threatening agents’ preferences and also to simulate their future behavior, providing for flexible, generalizable avoidance strategies. We tested this proposal across three preregistered experiments (total n=510) using a task in which participants collected rewards while avoiding one of several possible virtual threatening agents. A novel, model-based, hypothesis-testing inverse reinforcement learning computational model best explained participants’ inferences about threatening agents’ latent preferences, with participants using this inferred knowledge to enact generalizable, model-based avoidance strategies across different environments. Using tree-search planning models, we found that participants’ behavior was best explained by a planning algorithm that incorporated simulations of the threat’s goal-directed behavior, and that prior expectations about the threat’s predictability were linked to individual differences in avoidance. Together, our results indicate that humans use a cognitive map to determine threatening agents’ preferences, in turn facilitating generalized predictions of the threatening agent’s behavior and enabling flexible and effective avoidance.