We derive novel algorithms for optimization problems constrained by partial differential equations describing multiscale particle dynamics, including non-local integral terms representing interactions between particles. In particular, we investigate problems where the control acts as an advection ‘flow’ vector or a source term of the partial differential equation, and the constraint is equipped with boundary conditions of Dirichlet or no-flux type. After deriving continuous first-order optimality conditions for such problems, we solve the resulting systems by developing a link with computational methods for statistical mechanics, deriving pseudospectral methods in space and time variables, and utilizing variants of existing fixed-point methods as well as a recently developed Newton–Krylov scheme. Numerical experiments indicate the effectiveness of our approach for a range of problem set-ups, boundary conditions, as well as regularization and model parameters, in both two and three dimensions. A key contribution is the provision of software which allows the discretization and solution of a range of optimization problems constrained by differential equations describing particle dynamics.