In the United States . . .
Scope of Search Warrant:
To what extent can they search you and your belongings?
The scope of a search is limited by what is stated in the warrant. Not only must a warrant be supported by probably cause, it must also describe with particularity, "the place to be searched, and the persons or things to be seized." See U.S. Const. Amend. 4. For example, they cannot search a house if the warrant specifies the backyard, nor can they search for weapons if the warrant specifies marijuana plants. However, that doesn't mean that officers can seize only those items listed in the warrant. If, in the course of their search, police officers come across contraband or evidence of a crime that is not listed in the warrant, they can often seize it. When it comes to containers, the police are allowed to search anything that items could be inside. So, if they're looking for stolen TV's, they can't search a jewelry box or under the floor boards. However if they looking for something small, like bomb parts, just about everything is fair game.
To search you, the warrant would need to authorize the search of your person, or the police would need an independent justification to search you. For example, if they found explosives that were illegal to posses, they could conduct a search incident to arrest.
Can they search your entire computer?
Yes, assuming computers are within the scope of the warrant.
Compelling people to produce passwords of encryption keys:
If they find encrypted files can they detain you until you decrypt them?
This depends on your jurisdiction as it is a developing area of law and deal with 5th amendment. This is something that would not be done through a search warrant and would involve a separate proceeding.
In this situation, constitutional privilege against self-incrimination under the Fifth Amendment, U.S. Const. Amend. V, may be implicated.
Case where Court held producing passwords violated the 5th Amendment: The government's postindictment grand jury subpoena ordering the defendant to provide all passwords associated with his computer in order to secure evidence of child pornography allegedly contained in the computer, which spawned the three counts contained in the indictment, required the defendant to make a "testimonial communication," and thus the subpoena violated the defendant's Fifth Amendment privilege against compelled self-incrimination, where the government was not seeking documents or objects but instead was requiring the defendant to divulge through his mental processes his password that would be used to incriminate him, the district court in U.S. v. Kirschner, 823 F. Supp. 2d 665 (E.D. Mich. 2010), held. The court explained, an act is "testimonial," and thus protected by the Fifth Amendment privilege against self-incrimination when the accused is forced to reveal his knowledge of facts relating him to the offense or from having to share his thoughts and beliefs with the government. It is the extortion of information from the accused, the attempt to force him to disclose the contents of his own mind, that implicates the Fifth Amendment's Self-Incrimination Clause, the court said.
Case where Court held producing passwords did not violate the 5th Amendment:
The district court in U.S. v. Fricosu, 841 F. Supp. 2d 1232 (D. Colo. 2012), recognizing that production of a document may fall within the Fifth Amendment's privilege against self-incrimination since it acknowledges that the document exists, that it is in the possession or control of the producer, and that it is authentic, held that the defendant's Fifth Amendment privilege against self-incrimination was not implicated by requiring her to produce the unencrypted contents of a computer where the government knew of the existence and location of the computer's files; a preponderance of the evidence established either that the computer belonged to the defendant or that she was its sole or primary user, such that she had the ability to access its encrypted contents; and the government had offered her immunity, precluding it from using her act of producing those unencrypted contents against her. The court determined, also, that a preponderance of the evidence, in a motion to compel production of the unencrypted contents of the computer, found during a search of the defendant's residence, showed that either the computer belonged to her or that she was its sole or primary user, such that she could access its encrypted contents, supporting the decision to compel her to produce those unencrypted contents, where the defendant acknowledged, during a telephone conversation with her ex-husband, that she owned or had such a computer, the contents of which were accessible only by entry of a password, and the computer, which was found in her bedroom, was identified with her name.
This issues probably will not be decided one way or the other until the supreme court rules on it.
If they find a password safe can they force you to give them a password and >then can they log into all accounts you have stored in it?
When you say password safe, I am assuming you mean password management software. If so, see above.
If you don't give them the password but they find it written down
somewhere, can they still use it?
Yes, assuming their warrant allows them to search papers or it is in plain view.
Out of curiosity, do police ever actually do this? Find a password
protected file on a computer and go through all the papers in the desk
and try all possible passwords until they find one?
I'm not sure, but it wouldn't surprise me. Even if they don't have a warrant that covers papers, police have been known to bend the rules. I think someone with police experience could have a better answer for this.