I run the following python script code in Notebook in ArcGIS Pro. It works.
What are you passing in as the input_database argument? It should be an .sde file connected with a user that is able to rebuild indexes.
Rebuild Indexes (Data Management)—ArcGIS Pro | Documentation
Yes, I pass a .sde file in as the input_database argument.
The following code are same running in Notebook in ArcGIS Pro and VS code.
arcpy.management.RebuildIndexes(input_database=database,include_system="NO_SYSTEM",in_datasets=dataset,delta_only="ALL")
Added import arcpy in VS code.
Thank you!
Forrest