Mental computations can be flexibly adjusted according to internal beliefs, contextual cues, sensory evidence, and desired outcomes. The mechanisms supporting this flexibility are not understood. In this talk, I will describe how cortical circuits support this flexibility during 1) motor planning, 2) mental transformation, and 3) Bayesian inference. Using a combination of task design, neurophysiology, and recurrent neural network modeling, we have found that the underlying computational principles can be gleaned from the structure and dynamics of population cortical activity. For example, to produce different time intervals, cortical circuits establish an internal model that inverts the desired interval to an appropriate speed command for driving population neural activity toward an action-triggering state. Flexible mental transformations are in turn supported by inputs and initial conditions that systematically control the behavior of cortical internal models. Finally, Bayesian inference is made possible by integrating inputs within a cortical network whose latent dynamics encode prior beliefs. I will use these results to introduce a novel and potentially general computation-through-dynamics (CTD) framework for understanding behaviorally relevant computations in terms of cortical dynamics. According to CTD, cortical networks establish a structured reservoir of latent dynamics capable of performing a variety of computations. Inputs and initial conditions exploit this substrate to rapidly and flexibly reconfigure the system to perform different mental computations. I will conclude by highlighting the strengths and limitations of CTD as a parsimonious framework for linking brain to behavior.