Can you be more specific here? Normally, when Congress tasks an agency with something, that tasking defines the contours of what is and isn't legal. Defining "legal" is Congress's job.
The FBI has had no problem hacking computers around the world, getting the legal cooperation required domestically and abroad, and winning court cases.