The term ‘perinatal environment’ refers to the period surrounding birth, which plays a crucial role in brain development. It has been suggested that dynamic communication between the neuro–immune system and gut microbiota is essential in maintaining adequate brain function. This interaction depends on the mother’s status during pregnancy and/or the newborn environment. Here, we show experimental and clinical evidence that indicates that the perinatal period is a critical window in which stress-induced immune activation and altered microbiota compositions produce lasting behavioral consequences, although a clear causative relationship has not yet been established. In addition, we discuss potential early treatments for preventing the deleterious effect of perinatal stress exposure. In this sense, early environmental enrichment exposure (including exercise) and melatonin use in the perinatal period could be valuable in improving the negative consequences of early adversities. The evidence presented in this review encourages the realization of studies investigating the beneficial role of melatonin administration and environmental enrichment exposure in mitigating cognitive alteration in offspring under perinatal stress exposure. On the other hand, direct evidence of microbiota restoration as the main mechanism behind the beneficial effects of this treatment has not been fully demonstrated and should be explored in future studies.