A rock failure process analysis model, RFPA2D code, a two-dimensional numerical code, were proposed. The code not only satisfied the global equilibrium, strain consistent and nonlinear constitutive relationship of rock and soil materials but also took into account the heterogeneous characteristics of rock materials at macroscopic and microscopically level. The failure behavior of tunnel could be simulated by this numerical model. The model could realistically simulate the fracture behavior of tunnel by excavation loading, strength limits, and post peak response for both tension and compression. As the proposed method was used to conduct the stability analysis of tunnel, the safety factor of tunnel was defined as the ratio of actual shear strength parameter to critical failure shear strength parameter. Not only the safety factor of tunnel with specific physics meaning can be obtained, but also the overall failure process and the location of failure surface may also be determined at the same time.