forked from johnny603/lux
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsandbox_audit.py
More file actions
25 lines (21 loc) · 766 Bytes
/
Copy pathsandbox_audit.py
File metadata and controls
25 lines (21 loc) · 766 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import json
import os
from datetime import datetime, timezone
from typing import Any, Dict, Optional
def audit_path() -> str:
return os.getenv(
"LUX_SANDBOX_AUDIT_LOG",
os.path.expanduser("~/.lux/sandbox-audit.jsonl"),
)
def record_execution(event: Dict[str, Any], path: Optional[str] = None) -> None:
"""Append one privacy-conscious sandbox event without exposing submitted source."""
target = path or audit_path()
directory = os.path.dirname(target)
if directory:
os.makedirs(directory, exist_ok=True)
entry = {
"at": datetime.now(timezone.utc).isoformat(),
**event,
}
with open(target, "a", encoding="utf-8") as handle:
handle.write(json.dumps(entry, sort_keys=True) + "\n")