To address the issue of data privacy leakage that users may encounter when using code generation tools like Copilot,a privacy protection strategy for online code generation called PrivCode was proposed.Considering that current machine learning privacy protection strategies are often designed on the premise of a white-box model,which is difficult to apply to large models with unknown structures,Copilot was treated as a black-box and a proxy server was introduced using this strategy.Requests from multiple users were mixed by using Mix-Net,thereby breaking the mapping relationship between users and code generation requests.Secure delivery of code suggestions to users was ensured through the 1-out-of-N oblivious transfer.Three defined properties are satisfied and its practicality in real-world scenarios is indicated by experimental results.This strategy keeps a balance between user security and usage requirements.