API Reference
set_restricted

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

  • restricted bool, optional
    Pass True to enable static restricted mode. False is not accepted because it would weaken restriction.

  • restricted_context ContextVar, optional
    A context variable, or another object with a compatible get() method, used to dynamically decide whether memo reflection access is restricted. A truthy get() value enables restricted mode. A false value, or an unset context variable, leaves access unrestricted.

  • prefix str, 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

  • RuntimeError if the requested change would weaken restriction, replace an existing restricted context, add a context after static restricted mode, combine restricted=True with restricted_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.