Formation mechanism of hyperfragments with strangeness s=-1 and s=-2 in collisions of antikaons on nuclei has been investigated within a microscopic transport model. Dynamics of pseudoscalar mesons and hyperons is modeled within the transport model, in which all possible reaction channels for creating hyperons such as the elastic scattering, resonance production and decay, strangeness exchange reaction and direct strangeness production in meson-baryon and baryon-baryon collisions have been included. A coalescence approach is developed for constructing hyperfragments in phase space and the decay process is described with a statistical approach. It is found that the $\Xi^{-}$ production is correlated to the K$^{+}$ formation and the hyperons $\Lambda$ and $\Sigma$ are created within a broad rapidity region. The production cross sections of nucleonic fragments and hyperfragments weakly depends on the incident momentum. The yields of $\Lambda-$ hyperfragments are the six order of magnitude of $\Xi^{-}-$ hyperfragments.