Most flag states and most operators apply a strict alcohol limit (typically 0.05% blood alcohol or zero on duty) and a zero-tolerance illicit-drug policy. STCW Code Section A-VIII/2 requires watchkeepers to be free from impairment from drugs or alcohol. Random and 'for cause' testing is permitted under most operators' SMS and most CBAs. A positive test is normally grounds for immediate repatriation at the seafarer's cost, possible CoC suspension, and reporting to the flag state. If you take prescription medication, declare it in advance and carry the prescription.
STCW Code Section A-VIII/2 Part 5 (fitness for duty). ILO MLC 2006 Standard A4.3 (on-board safety). OCIMF Guidelines for the Control of Drugs and Alcohol Onboard Ship. SAMHSA-aligned chain-of-custody procedures are the industry-standard testing protocol. National laws (Norway, UK, US, Australia) impose criminal liability for operating a vessel impaired.