Abstract. The ability to update the program code installed on wireless sensor nodes plays an import role in the highly dynamic environments sensor networks are often deployed in. Such code update mechanisms should support flexible reconfiguration and adaptation of the sensor nodes but should also operate in an energy and time efficient manner. In this paper, we present FlexCup, a flexible code update mechanism that minimizes the energy consumed on each sensor node for the installation of arbitrary code changes. We describe two different versions of FlexCup and show, using a precise hardware emulator, that our mechanism is able to perform updates up to 8 times faster than related code update algorithms found in the literature, while consuming only an eighth of the energy.