Microporous metal-organic frameworks (MOFs) that display permanent porosity show great promise for a myriad of purposes. The potential applications of MOFs can be developed further and extended by encapsulating various functional species (for example, nanoparticles) within the frameworks. However, despite increasing numbers of reports of nanoparticle/MOF composites, simultaneously to control the size, composition, dispersed nature, spatial distribution and confinement of the incorporated nanoparticles within MOF matrices remains a significant challenge. Here, we report a controlled encapsulation strategy that enables surfactant-capped nanostructured objects of various sizes, shapes and compositions to be enshrouded by a zeolitic imidazolate framework (ZIF-8). The incorporated nanoparticles are well dispersed and fully confined within the ZIF-8 crystals. This strategy also allows the controlled incorporation of multiple nanoparticles within each ZIF-8 crystallite. The as-prepared nanoparticle/ZIF-8 composites exhibit active (catalytic, magnetic and optical) properties that derive from the nanoparticles as well as molecular sieving and orientation effects that originate from the framework material.