A 3D numerical model for the ablation of pellets and shattered pellet injection (SPI) fragments in tokamaks in the plasma disruption mitigation and fueling parameter space has been developed based on the Lagrangian particle code [R. Samulyak, X. Wang, H.-S. Chen, Lagrangian Particle Method for Compressible Fluid Dynamics, J. Comput. Phys., 362 (2018), 1-19]. The pellet code implements the low magnetic Reynolds number MHD equations, kinetic models for the electronic heating, a pellet surface ablation model, an equation of state that supports multiple ionization states, radiation, and a model for grad-B drift of the ablated material across the magnetic field. The Lagrangian particle algorithm is highly adaptive, capable of simulating a large number of fragments in 3D while eliminating numerical difficulties of dealing with the tokamak background plasma. The code has achieved good agreement with theory for spherically symmetric ablation flows. Axisymmetric simulations of neon and deuterium pellets in magnetic fields ranging from 1 to 6 Tesla have been compared with previous simulations using the FronTier code, and very good agreement has also been obtained. The main physics contribution of the paper is a detailed study of the influence of 3D effects, in particular grad-B drift, on pellet ablation rates and properties of ablation clouds. Smaller reductions of ablation rates in magnetic fields compared to axially symmetric simulations have been demonstrated because the ablated material is not confined to narrowing channels in the presence of grad-B drift. Contribution of various factors in the grad-B drift model has also been quantified.