The 'code' was the serial number of his pacemaker. There must have been a way of accessing it via computer and sending it the wrong signals, thus causing the heart attack.
Brody sent the code from the office via his mobile phone; the senator then came in, so Brody was present in the office when the senator died (as the code was quickly acted upon). Nasir was holding Carrie hostage, and released her in exchange for the code from Brody.