Abstract Humans have a remarkable ability to flexibly interact with the environment. A compelling demonstration of this cognitive flexibility is our ability to respond correctly to novel contextual situations on the first attempt, without prior rehearsal. We refer to this ability as ‘ad hoc self-programming’: ‘ad hoc’ because these new behavioral repertoires are cobbled together on the fly, based on immediate demand, and then discarded when no longer necessary; ‘self-programming’ because the brain has to configure itself appropriately based on task demands and some combination of prior experience and/or instruction. The overall goal of our research effort is to understand the neurophysiological and computational basis for ad hoc self-programmed behavior. Our previous U01 project (NS 108923) focused on how these programs of action are initially created. Our results thus far have revealed tantalizing notions of how the brain represents these programs and navigates through them. In this proposal, therefore, we focus on the question of how these mental programs are executed. Based on our preliminary findings and critical conceptual work, we propose that the medial temporal lobe (MTL) and ventral prefrontal cortex (vPFC) creates representations of the critical elements of these mental programs, including concepts such as ‘rules’ and ‘locations’, to allow for effective navigation through the algorithm. These data suggest the existence of an ‘algorithmic state space’ represented in medial temporal and prefrontal regions. This proposal aims to understand the neurophysiological underpinnings of this algorithmic state space in humans. By studying humans, we will profit from our species’ powerful capacity for generalization to understand how such state spaces are constructed. We therefore leverage the unique opportunities available in human neuroscience research to record from single cells and population-level signals, as well as to use intracranial stimulation for causal testing, to address this challenging problem. In Aim 1 we study the basic representations of algorithmic state space using a novel behavioral task that requires the immediate formation of unique plans of action. Aim 2 directly compares representations of algorithmic state space to that of physical space by juxtaposing balanced versions of spatial and algorithmic tasks in a virtual reality (VR) environment. Finally, in Aim 3, we test hypotheses regarding interactions between vPFC and MTL using intracranial stimulation.