Cockpen is a parish in Midlothian, Scotland, containing at its north-west corner the town of Bonnyrigg, which lies two miles (3.2 km) south-west of Dalkeith.
It is bounded on the west and north by the parish of Lasswade, on the east, by Newbattle and on the south by Carrington.
From the 12th to the 19th centuries the parish of Cockpen comprised the same area as the Barony of Dalhousie (a corruption of Dalwolsie).
[6] There have been a succession of fortresses at their seat, Dalhousie Castle, which lies on the north bank of the South Esk.
The parish church is one mile (1.6 km) south-east of Bonnyrigg on rising land on the west bank of Dalhousie Burn.