Usually, police are not allowed to search you unless they have a warrant or your consent (your agreement). But there are exceptions to the warrant requirement, and “consent” can be tricky. Here are some of the exceptions in which police are allowed to search you without your consent or a warrant:
If a person is being detained for investigative purposes, and a police officer has reasonable grounds to believe that their safety or that of others is at risk, the officer may engage in a protective pat-down search of the detained individual.
If a person is arrested, and the police have a valid reason (protecting themselves from concealed weapons, making sure evidence is not destroyed, discovering evidence), then the police can search the arrested person within a reasonable period of time after the arrest. E.g., if an officer has reason to believe that evidence would be lost or destroyed while they are getting a warrant, or that the person being taken into custody may have concealed weapons on their person that could pose a threat to the safety of the arresting officer.
Usually, you have a reasonable expectation of privacy (and are entitled to privacy) in your car. But if a person is pulled over while driving, the police can conduct a “plain view” search of the vehicle (looking around) without entering it. If the police see something, this may give them reason to conduct a search inside the car.
If a 911 call directs the police to your home or vehicle, the responding officers are allowed to briefly search your home or vehicle if the call gives them reason to fear for their own safety or for the safety of others. This search may include the trunk or some other compartment of your vehicle.
BUT in situations in which you have a greater “expectation of privacy” – for example, if the privacy invasion is more serious, like a strip search or DNA test – there are more restrictions on when and how police can conduct these searches.