Learn Apex
Apex managed sharing
Use Apex to insert, update, or delete share rows (e.g. AccountShare) so runtime logic can grant or revoke access — still subject to your design and tests.
Shares

Manual sharing in the UI creates share rows. Apex managed sharing does the same thing in code — useful when rules are too static and you need to react to field changes, teams, or external ids.

Toy: run Apex to insert a share

User Sam’s access

No extra share

Storage

Illustrative shape (simplified)
AccountShare sh = new AccountShare();
sh.AccountId = acct.Id;
sh.UserOrGroupId = samUserId;
sh.AccountAccessLevel = 'Read';
sh.RowCause = Schema.AccountShare.RowCause.Manual; // or custom Apex cause
insert sh;

Real code uses correct object types, error handling, and tests. RowCause values depend on your org — read Salesforce docs for the share object you need.