The statistical mechanics of self-avoiding walks (SAW) or of the O( n)-loop model on a two-dimensional random surface are shown to be exactly solvable. The partition functions of SAW and surface configurations (possibly in the presence of vacuum loops) are calculated by planar diagram enumeration techniques. Two critical regimes are found: a dense phase where the infinite walks and loops fill the infinite surface, the non-filled part staying finite, and a dilute phase where the infinite surface singularity on the one hand, and walk and loop singularities on the other, merge together. The configuration critical exponents of self-avoiding networks of any fixed topology G, on a surface with arbitrary genus H, are calculated as universal functions of G and H. For self-avoiding walks, the exponents are built from an infinite set of basic conformal dimensions associated with central charges c = −2 (dense phase) and c = 0 (dilute phase). The conformal spectrum Δ L , L ⩾ 1 associated with L-leg star polymers is calculated exactly, for c = −2 and c = 0. This is generalized to the set of L-line “watermelon” exponents Δ L of the O( n) model on a random surface. The results are in perfect agreement with the conformal theory of Knizhnik, Polyakov and Zamolodchikov describing matter fields coupled to 2D quantum gravity. The infinite series of dimensions Δ L dressed by gravity calculated here, together with the corresponding SAW conformal dimensions Δ L (0) in the plane, known independently from Coulomb-gas techniques, match the KPZ relation Δ − Δ (0) = Δ(1 − Δ) κ , where c = 1 − 6(1 − κ) 2 k . This provides a cross check of Coulomb-gas techniques, the KPZ conformal theory of matter fields with 2D quantum gravity and the universality of random lattices. The divergences of the partition functions of self-avoiding networks on the random surface, possibly in the presence of vacuum loops, are shown to satisfy a factorization theorem over the vertices of the network. This provides a proof, in the presence of a fluctuating metric, of a result conjectured earlier in the standard plane. From this, the value of the string susceptibility γ str( H, c) is extracted for a random surface of arbitrary genus H, bearing a field theory of central charge c, or equivalently, embedded in d c dimensions. Lastly, by enumerating spanning trees on a random lattice, we solve the similar problem of hamiltonian walks on the (fluctuating) Manhattan covering lattice. We also obtain new results for dilute trees on a random surface.