Smart environments represent a relatively uncharted ICT territory where plenty of sensor and actuator devices can be enrolled on-demand in order to realize high value-added services. A few application scenarios, such as Smart Cities, have already been explored. However, in order to finally enable such a paradigm, several issues have to be dealt with. In particular, from a developer perspective the high degree of heterogeneity for devices (ranging from cheap sensors to smartphones) could represent a hurdle for software design. In this paper, we present an innovative architecture that aims at providing a common reference platform for repurposing of devices i.e, reshaping their operational behavior for emergent and unforeseen requirements. Thanks to its modular and plugin based design, the proposed architecture is poised to ease implementation of both low-level (e.g., device discovery, code compilation, binary deployment) and high-level (e.g., service composition, data management) duties. We present the general architecture, then focusing on device-side aspects, while also providing two simple use cases that demonstrate the suitability of the proposed approach.