I discuss the answer to your question at length in my book and suggest that you read the more detailed explanation there.
For federal clerks, here is a summary of the official word on this from the Administrative Office of the United States Courts: Pursuant to the Treasury and General Government Appropriations Act, 2000, Public Law No. 106-58, section 605 (September 29, 1969), "any judicial employee assigned in the continental United States compensated with federal funds must be a United States citizen or otherwise eligible for federal employment within the United States. A non-citizen of the United States may be employed by the federal judiciary to work for courts located in Puerto Rico, Guam, the Virgin Islands, Northern Mariana Islands and Hawaii." Thus, judicial clerkships fall within the general restrictions on the use of appropriated funds for payment of federal salaries to individuals who are not citizens of the United States.
Note that these restrictions do not apply to employment outside of the continental United States; hence you may pursue a federal clerkship in the islands listed above. Other exceptions may be applicable, both statutory and by treaty with certain countries, such as allies of the U.S. For additional information regarding the employment of non-United States citizens, you are advised to consult the United States Office of Personnel Management website at http://www.opm.gov/employ/html/non_cit.htm
or call the Office of General Counsel at the Administrative Office of the U.S. Courts at (202) 502-1100.
So, if you want to pursue a federal clerkship in the continental U.S., you need to determine whether your country falls within the prohibition or is the subject of a treaty or statutory exception. I have some of those exceptions listed here (and in my book); and refer you to the official website and number, above, for the most recent list. See Strauss, Debra M., Behind the Bench: The Guide to Judicial Clerkships
(BarBri Group 2002) at pp. 173-4.