Prestellar cores are compact, very high density structures observable in molecular and dust continuum emission, embedded within the filaments that comprise most of the mass in nearby dark molecular clouds and GMCs. These cores are the immediate precursors of protostars, and the distribution of initial properties of star-disk systems (mass, angular momentum, and magnetization) are established by the core formation process. In particular, it has been argued from observations that the stellar IMF is directly inherited from the prestellar core mass function (CMF). However, it has not been understood theoretically exactly how cores form, or how core properties depend on the parameters of the parent molecular cloud. Classical core evolution models rely on ambipolar diffusion to produce low mass, magnetically supercritical cores, but the timescales are too long, and core formation stages are not addressed. I will describe numerical hydrodynamic and MHD simulations of core formation in turbulent clouds, focusing on the detailed dynamics of how cores grow, and investigating how the CMF depends on the properties of the surrounding turbulent cloud. We show that low-mass, magnetically supercritical cores form by a two-stage dynamical process in post-shock layers, with ambipolar diffusion playing a limited role. More generally, we find that the mass at the CMF peak depends on the total pressure in post-shock layers where cores form. For conditions similar to those in local clouds, core properties agree with observations. The scalings predicted by our models also have intriguing implications for non-universal IMFs.