In this article, we review some recent theoretical results about intrusion and extrusion of non-wetting liquids in and out of cavities of nanotextured surfaces and nanoporous materials. Nanoscale confinement allows these processes to happen at conditions which significantly differ from bulk phase coexistence. In particular, the pressure at which a liquid penetrates in and exits from cavities is of interest for many technological applications such as energy storage, dissipation, and conversion, materials with negative compressibility, ion channels, liquid chromatography, and more. Notwithstanding its technological interest, intrusion/extrusion processes are difficult to understand and control solely via experiments: the missing step is often a simple theory capable of providing a microscopic interpretation of the results, e.g., of liquid porosimetry or other techniques used in the field, especially in the case of complex nanoporous media. In this context, simulations can help shedding light on the relation between the morphology of pores, the chemical composition of the solids and liquids, and the thermodynamics and kinetics of intrusion and extrusion. Indeed, the intrusion/extrusion kinetics is determined by the presence of free energy barriers and special approaches, the so-called rare event techniques, must be used to study these processes. Usually, rare event techniques are employed to investigate processes occurring in relatively simple molecular systems, while intrusion/extrusion concerns the collective dynamics of hundreds to thousands of degrees of freedom, the molecules of a liquid entering in or exiting from a cavity, which, from the methodological point of view, is itself a challenge.