  We consider a newly-born millisecond magnetar, focusing on its interaction
with the dense stellar plasma in which it is initially embedded. We argue that
the confining pressure and inertia of the surrounding plasma acts to collimate
the magnetar's Poynting-flux-dominated outflow into tightly beamed jets and
increases its magnetic luminosity. We propose this process as an essential
ingredient in the magnetar model for gamma-ray burst and asymmetric supernova
central engines. We introduce the ``pulsar-in-a-cavity'' as an important model
problem representing a magnetized rotating neutron star inside a collapsing
star. We describe its essential properties and derive simple estimates for the
evolution of the magnetic field and the resulting spin-down power. We find that
the infalling stellar mantle confines the magnetosphere, enabling a gradual
build-up of the toroidal magnetic field due to continuous twisting. The growing
magnetic pressure eventually becomes dominant, resulting in a
magnetically-driven explosion. The initial phase of the explosion is
quasi-isotropic, potentially exposing a sufficient amount of material to
$^{56}$Ni-producing temperatures to result in a bright supernova. However, if
significant expansion of the star occurs prior to the explosion, then very
little $^{56}$Ni is produced and no supernova is expected. In either case, hoop
stress subsequently collimates the magnetically-dominated outflow, leading to
the formation of a magnetic tower. After the star explodes, the decrease in
bounding pressure causes the magnetic outflow to become less beamed. However,
episodes of late fallback can reform the beamed outflow, which may be
responsible for late X-ray flares.
