Spacecraft must possess the capability of autonomous obstacle avoidance to ensure flight safety. Currently, the available methods for obstacle avoidance guidance are primarily deterministic and will fail with large state estimation errors, which necessitates the robustness of guidance algorithms towards uncertainties. A collision probability sliding mode guidance method is presented for the autonomous obstacle avoidance of spacecraft. Based on the multiple sliding mode surfaces guidance law, a sliding mode structure is proposed to realize obstacle avoidance in the presence of state uncertainty, taking into account the collision probability constraint. First, A multiple power reaching law is designed to enhance the convergence speed of the first sliding mode surface, so that the spacecraft system reaches the target state within a finite time. Subsequently, the collision probability gradient information function is defined according to the relative relation between the spacecraft and obstacles. This function is then combined with the improved reaching law to develop the second sliding mode surface. The sliding mode surface can quantify the collision probability in real-time, and generate corresponding obstacle avoidance guidance commands to prompt the spacecraft to move away from the obstacles according to the magnitude of collision probability, which is robust to the state uncertainty. The capability of the proposed guidance algorithm is validated by a series of simulations, including scenarios involving asteroid landing and spacecraft rendezvous, and the effectiveness and robustness in the face of uncertainties are confirmed.