I have documented the Osiris calls related to registering triggers and getting events from entering/leaving them:
https://docs.larian.game/Osiris/API/TriggerRegisterForCharacter (you can find related calls starting from that page).
Since you want to track all characters' presence in that trigger, it's best to use an event trigger as mentioned in the Notes on that page. You can then use the following Osiris code:
QRY
QRY_DoorIsOpenOrOpening((ITEMGUID)_Door)
AND
DoorIsOpening(_Door, 1)
THEN
DB_NOOP(1);
QRY
QRY_DoorIsOpenOrOpening((ITEMGUID)_Door)
AND
ItemIsOpen(_Door, 1)
THEN
DB_NOOP(1);
IF
// anyone leaves the trigger
CharacterLeftTrigger(_, TRIGGERGUID_S_YourBoxTrigger_UUID)
AND
// no one is left in the trigger
NOT DB_InRegion(_, TRIGGERGUID_S_YourBoxTrigger_UUID)
AND
// the door is currently open or opening
QRY_DoorIsOpenOrOpening(ITEMGUID_S_YourDoor_UUID)
THEN
ItemClose(ITEMGUID_S_YourDoor_UUID);
For details on how to structure your Osiris code, please see
https://docs.larian.game/Osiris_Design_Patterns#Program_InitialisationEdit: For a more concrete start on setting up your story scripting, see Windemere's
https://docs.larian.game/Tutorial_-_Implementing_a_Basic_Quest