The Feynman-Kac equations are a type of partial differential equations describing the distribution of functionals of diffusive motion. The probability density function (PDF) of Brownian functionals satisfies the Feynman-Kac formula, being a Schr\"{o}dinger equation in imaginary time. The functionals of no-Brownian motion, or anomalous diffusion, follow the fractional Feynman-Kac equation [J. Stat. Phys. 141, 1071-1092, 2010], where the fractional substantial derivative is involved. Based on recently developed discretized schemes for fractional substantial derivatives [arXiv:1310.3086], this paper focuses on providing algorithms for numerically solving the forward and backward fractional Feynman-Kac equations; since the fractional substantial derivative is non-local time-space coupled operator, new challenges are introduced comparing with the general fractional derivative. Two ways (finite difference and finite element) of discretizing the space derivative are considered. For the backward fractional Feynman-Kac equation, the numerical stability and convergence of the algorithms with first order accuracy are theoretically discussed; and the optimal estimates are obtained. For all the provided schemes, including the first order and high order ones, of both forward and backward Feynman-Kac equations, extensive numerical experiments are performed to show their effectiveness.