In order to answer this question, you should think about the attributes that an undercover police officer would need. Then you can think about yourself and ask whether you have those attributes. Let us look at some attributes that would be important.
The ability to play a part. As the undercover officer, you would be like an actor in a play. You would have to pretend to be something you are not. Would you be good at assuming a role and sticking with it?
The ability to remain calm under stress. An undercover officer might often get into situations where their cover looks like it is getting blown. They might get into situations where they are in danger. They have to remain as calm as possible at such times.
The ability to think on your feet. An undercover officer would be exposed to many situations in which they have to think quickly so as to figure out how to react. A person who needs a long time to think about situations might not do well.
If you have these attributes, you would likely make a good undercover officer. If not, you might not be suitable.