def set_restricted(*, restricted: Optional[bool] = None, restricted_context = None, prefix: Optional[str] = None) -> None
Increases restricted memo reflection access for the workspace or for one already-open prefix.
Introduced in dbzero 0.4.2.
Use this function when a process initializes dbzero without restriction and later needs to enter a stricter mode. Restriction can only become stronger: unrestricted can become context-controlled, and context-controlled can become statically restricted. Static restricted mode cannot be weakened.
set_restricted() does not make prefixes read-only. It restricts reflection-style access through memo objects and restricted method proxies.
Parameters
-
restrictedbool, optional
PassTrueto enable static restricted mode.Falseis not accepted because it would weaken restriction. -
restricted_contextContextVar, optional
A context variable, or another object with a compatibleget()method, used to dynamically decide whether memo reflection access is restricted. A truthyget()value enables restricted mode. A false value, or an unset context variable, leaves access unrestricted. -
prefixstr, optional
Name of an already-open prefix to update. If omitted, dbzero updates the workspace default and eligible currently open prefixes.
Returns
This method does not return any value.
Raises
RuntimeErrorif the requested change would weaken restriction, replace an existing restricted context, add a context after static restricted mode, combinerestricted=Truewithrestricted_context, or target a prefix that is not open.
Examples
Add Dynamic Restricted Mode
from contextvars import ContextVar
import dbzero as db0
agent_restricted = ContextVar("agent_restricted", default=False)
db0.init("./app-data")
db0.open("agent-memory")
# The workspace default and eligible open prefixes now use the context.
db0.set_restricted(restricted_context=agent_restricted)
token = agent_restricted.set(True)
try:
run_agent_tool()
finally:
agent_restricted.reset(token)Restrict One Prefix
from contextvars import ContextVar
import dbzero as db0
agent_restricted = ContextVar("agent_restricted", default=False)
db0.init("./app-data")
db0.open("host-config")
db0.open("agent-memory")
db0.set_restricted(prefix="agent-memory", restricted_context=agent_restricted)Only agent-memory is updated. Other open prefixes keep their current restriction level.
Upgrade to Static Restricted Mode
db0.set_restricted(restricted=True)Static restricted mode is terminal for the current process. After this call, the affected prefixes cannot be converted back to unrestricted mode or to context-controlled mode.