  In this paper we define and study a generalization of the Belinson-Drinfeld
Grassmannian to the case where the curve is replaced by a smooth projective
surface $X$, and the trivialization data are given on loci suitably associated
to a nonlinear flag of closed subschemes. In order to do this, we first
establish some general formal gluing results for moduli of almost perfect
complexes, perfect complexes and torsors. We then construct a simplicial object
$Fl_X$ of flags of closed subschemes of a smooth projective surface $X$,
naturally associated to the operation of taking union of flags. We prove that
this simplicial object has the 2-Segal property. For an affine complex
algebraic group $G$, we finally define a derived, flag analog $Gr_X$ of the
Beilinson-Drinfeld Grassmannian of $G$-bundles on the surface $X$, and show
that most of the properties of the Beilinson-Drinfeld Grassmannian for curves
can be extended to our flag generalization. In particular, we prove a
factorization formula, the existence of a canonical flat connection, and define
a chiral product on suitable sheaves on $Fl_X$ and on $Gr_X$. We also sketch
the construction of actions of flags analogs of the loop group and of the
positive loop group on $Gr_X$. To fixed ``large'' flags on $X$, we associate
``exotic'' derived structures on the classical stack of $G$-bundles on $X$.
Analogs of the flag Grassmannian for other Perf-local stacks (replacing the
stack of $G$-bundles) are briefly considered, and flag factorization is proved
for them, too.
