In this paper we study insolvency cascades in an interbank system, in which banks are permitted to insure their loans with credit default swaps (CDSs) sold by other banks. We show that, by properly shifting financial exposures from one institution to another, a CDS market can be designed to rewire the network of interbank exposures, in ways that make it more resilient to insolvency cascades. In devising a systemic insurance surcharge to be added to the CDS spread, a regulator will consider information about the topology of the interbank network. Thus, CDS contracts are effectively penalized according to how much they contribute to increasing systemic risk. CDS contracts that reduce systemic risk remain untaxed. We simulate this regulated CDS market using an agent-based model (CRISIS macro-financial model) and demonstrate that it leads to an interbank system that is more resilient to insolvency cascades.