We have designed an assay that measures approach and avoidance behaviors in head-fixed mice at millisecond timescale, is compatible with standard electrophysiological and optical methods for measuring neuronal activity, and requires no training. The Virtual Burrow Assay simulates a scenario in which a mouse, poised at the threshold of its burrow, evaluates whether to exit the enclosure or to retreat inside. The assay provides a sensitive readout of habituation, discrimination and exploration, as well as avoidance of both conditioned and innately aversive cues.