Almost 40 persons, including students, journalists and political activists, have been detained in the last three weeks, apparently in connection with recent demonstrations against the government's racial segregation policies.

The arrests bring to 145 the number of people now being held under South African security legislation, according to records kept by the South African Institute of Race Relations, a private organization opposed to the policy of apartheid.

The number held under the security law as higher until last Friday, when 57 trade unionists, held for several weeks in the black homeland of Ciskei, where formally charged with holding illegal gatherings and disturbing the peace, it was disclosed Wednesday.

Police decline to say how many persons they are holding under the security laws which allow for indefinite detention without trail.

The detentions stand in sharp contrast to government appeals, echoed almost daily in the Afrikaans-language press, for better race relations and a greater role for black workers in the economy. They appear to be in response to a number of recent bombings, strikes and student protests attributed to black nationalists.

Among those recently detained are two well-known black journalists, Thami Mazwai and Zwelakhe Sisulu.

Also being held are Aziz Jardine, an 18-year-old Colored (mixed-race) student leader whose detention sparked off two days of high school student unrest in a Colored section of Johannesburg, and white university student leader Andrew Boraine, the son of an opposition member of Parliament.

On Thursday, police detained 10 black students from the University of Witwatersrand in a predawn raid. All are members of the Black Students Society.

Police have also confirmed the arrest of eight prominent student leaders of the Soweto student unrest in 1976. The eight who all fled the country in 1977, were arrested last week after clandestinely returning to Soweto.

On several recent occasions, the South African Defense Force, previously reluctant to become involved in domestic security operations, has assisted the police. Soldiers have often been seen at the roadblocks that are frequently placed on roads leading into black and Colored neighborhoods. And on June 5 the Army cardoned off a Colored section of Johannesburg while police carried out a house-to-house search for students following two days of unrest there sparked by the detention of Jardine.

The search and police use of tear gas and rubber whips against the Colored leaders who told Police Minister Louis Le Grange last week that "the violence has been provoked and that there appears to be a very strong underlying motive to deal with issues in the community in a violent and brutal manner."

Leaders in Soweto were angry after police fired tear gas outside the door of Regina Mundi church June 16 where about 5,000 people were holding a service for those who died in the 1976 riots.

The police crackdown is in part a response to bombings the last week in May to protest the government's celebrations of South Africa's 1961 break with the British Commonwealth.

In addition, there have been a number of major strikes by black workers mainly in the auto industry.

Police decline to say whether they believe any specific organization is behind all these activities, but articles in the Afrikaans-language press quoting police sources, have noted that pamphlets calling for work boycotts have used language and ideas associated with the banned black nationalist movement, the African National Congress. The congress did claim responsibility for the bombings.

Although there is no evidence of any conspiracy behind all these events, the police are not wrong in believing there is a widespread and growing support for the African National Congress because of the authorities' refusal to allow black political activity.

On Sunday an ANC flag was paraded around the black township of Alexandra. Pamphlets put out by white university students openly quote from the ANC constitution; two black policemen are on trial for being ANC members and the ANC flag was raised at the black University of Turfloop.