We construct vertex algebras associated to divisors $S$ in toric Calabi-Yau threefolds $Y$, satisfying conjectures of Gaiotto-Rapcak and Feigin-Gukov, and in particular such that the characters of these algebras are given by a local analogue of the Vafa-Witten partition function of the underlying reduced subvariety $S^{red}$. These results are part of a broader program to establish a dictionary between the enumerative geometry of coherent sheaves on surfaces and Calabi-Yau threefolds, and the representation theory of vertex algebras and affine Yangian-type quantum groups.