We describe a multiscale finite element (FE) solver for elliptic or parabolic problems with highly oscillating coefficients. Based on recent developments of the so-called heterogeneous multiscale method (HMM), the algorithm relies on coupled macro- and microsolvers. The framework of the HMM allows to design a code whose structure follows the classical finite elements implementation at the macro level. To account for the fine scales of the problem, elementwise numerical integration is replaced by micro FE methods on sampling domains. We discuss a short and flexible FE implementation of the multiscale algorithm, which can accommodate simplicial or quadrilateral FE and various coupling conditions for the constrained micro simulations. Extensive numerical examples including three dimensional and time dependent problems are presented illustrating the efficiency and the versatility of the computational strategy. (C) 2009 Elsevier B.V. All rights reserved.