In the information age, frequent information exchange has provided a breeding ground for the spread of computer viruses. The significant losses caused by computer virus attacks have long rung the alarm for information security. From academia to businesses, and even to government, everyone remains highly vigilant about information security. Researchers have put forward various approaches to combat computer viruses, involving innovative efforts in both the hardware and software aspects, as well as theoretical innovation and practical exploration. This article is dedicated to theoretical exploration, specifically investigating the stability of a computer virus model, known as SLBRS, from the perspective of optimal control. Firstly, a control system is introduced with the aim of minimizing the costs related to network detoxification and diminishing the percentage of computers impacted by the virus. Secondly, we employ the Pontryagin maximum principle to analyze the optimality of a control strategy for the proposed system. Thirdly, we validate the effectiveness of our theoretical analysis through numerical simulation. In conclusion, both theoretical analysis and numerical simulation reveal that the utilization of optimal control analysis to stabilize the SLBRS has been demonstrated to be advantageous in restoring contaminated computer network environments.