You would need to take a drug test to work for the USDS. To the best of my knowledge, you don't have to take a drug test to apply to 18F, although I believe that you may be asked the question as part of the application process for 18F.
Applying to 18F didn't require a drug test for me. The application process asks this question in the background check part (details at "security clearance" at the bottom of https://pages.18f.gov/joining-18f/how-to-apply/ for anyone curious), but answering yes to the "have you ever done federally-illegal drugs" question is not an automatic disqualification. It can be a disqualification depending on the details of the drug use.