We consider the optimal investment problem with random endowment in the presence of defaults. For an investor with constant absolute risk aversion, we identify the certainty equivalent, and compute prices for defaultable bonds and dynamic protection against default. This latter price is interpreted as the premium for a contingent credit default swap, and connects our work with earlier articles, where the investor is protected upon default. We consider a multiple risky asset model with a single default time, at which point each of the assets may jump in price. Investment opportunities are driven by a diffusion X taking values in an arbitrary region E⊆double-struckRd. We allow for stochastic volatility, correlation, and recovery; unbounded random endowments; and postdefault trading. We identify the certainty equivalent with a semilinear parabolic partial differential equation with quadratic growth in both function and gradient. Under minimal integrability assumptions, we show that the certainty equivalent is a classical solution. Numerical examples highlight the relationship between the factor process, market dynamics, utility‐based prices, and default insurance premium. In particular, we show that the holder of a defaultable bond has a strong incentive to short the underlying stock, even for very low default intensities.