Any county not desiring to work its workhouse prisoners may, through its county mayor, by direction of the county legislative body, contract with any other county for the custody and employment of such prisoners. The prisoners shall then be worked and guarded by the county contracting to take them and shall be subject to any rules that may be established by the workhouse commissioners of that county.