We use two-dimensional transverse laser cooling to produce an ultracold beam of YbF molecules. Through experiments and numerical simulations, we study how the cooling is influenced by the polarization configuration, laser intensity, laser detuning and applied magnetic field. The ultracold part of the beam contains more than $2 times 10^5$ molecules per shot and has a temperature below 200 $mu$K, and the cooling yields a 300-fold increase in the brightness of the beam. The method can improve the precision of experiments that use molecules to test fundamental physics. In particular, the beam is suitable for measuring the electron electric dipole moment with a statistical precision better than $10^{-30}$ e cm.