Entropic 2.14.3
Local-first agentic inference engine
Loading...
Searching...
No Matches
entropic::ScopedSandbox Class Reference

RAII directory swapper for sandbox-scoped tool execution. More...

#include <entropic/core/sandbox.h>

Public Types

using SwapDirFn = void(*)(const std::string &session_key, const std::filesystem::path &path, bool entering, void *user_data)
 Callback type for directory swapping.
 

Public Member Functions

 ScopedSandbox (SwapDirFn swap_fn, void *user_data, std::string session_key, const std::filesystem::path &sandbox_path, const std::filesystem::path &original_path)
 Construct and swap directories.
 
 ~ScopedSandbox ()
 Restore the original directory.
 
 ScopedSandbox (const ScopedSandbox &)=delete
 
ScopedSandbox & operator= (const ScopedSandbox &)=delete
 

Detailed Description

RAII directory swapper for sandbox-scoped tool execution.

Swaps the engine's tool working directory to the sandbox path on construction and restores it on destruction. Used by DelegationManager to route MCP server (filesystem, bash, …) calls into the sandbox during a delegation.

Version
2.1.5

Definition at line 331 of file sandbox.h.

Member Typedef Documentation

◆ SwapDirFn

using entropic::ScopedSandbox::SwapDirFn = void (*)( const std::string& session_key, const std::filesystem::path& path, bool entering, void* user_data)

Callback type for directory swapping.

The facade implements this to iterate the registered servers of the session's workspace and call entropic_mcp_server_set_working_dir() on each.

gh#160 (v2.13.0): carries the session key. The servers a swap must move are the ones the RUNNING SESSION's tools resolve against, and with concurrent_sessions on (gh#158) two sessions delegate at the same time — a swap that names no session is a swap that cannot be routed. gh#166 re-points the facade side of this at the session's workspace without touching the signature again.

entering distinguishes the two calls of a scope: the facade takes its per-workspace swap lock on entry and releases it on restore, which is what keeps two concurrent sandboxed delegations from interleaving their swaps on one set of server objects.

Parameters
session_keySession the delegation belongs to ("" = default).
pathNew working directory.
enteringTrue on sandbox entry, false on restore.
user_dataOpaque pointer (facade context).
Version
2.13.0

Definition at line 358 of file sandbox.h.

Constructor & Destructor Documentation

◆ ScopedSandbox()

entropic::ScopedSandbox::ScopedSandbox ( SwapDirFn  swap_fn,
void *  user_data,
std::string  session_key,
const std::filesystem::path &  sandbox_path,
const std::filesystem::path &  original_path 
)

Construct and swap directories.

Parameters
swap_fnDirectory swap callback (may be null — no-op).
user_dataOpaque pointer for swap_fn.
session_keySession whose tool root is being swapped.
sandbox_pathTarget sandbox directory.
original_pathDirectory to restore on destruction — the caller's ACTIVE root, which for a nested delegation is the parent's sandbox and not the project root (gh#160).
Version
2.13.0
Parameters
swap_fnDirectory swap callback.
user_dataOpaque pointer for swap_fn.
sandbox_pathTarget sandbox directory.
original_pathOriginal directory to restore. @dg_internal
Version
2.1.5

Definition at line 634 of file sandbox.cpp.

◆ ~ScopedSandbox()

entropic::ScopedSandbox::~ScopedSandbox ( )

Restore the original directory.

Restore the caller's active directory (gh#160).

Version
2.1.5

@dg_internal

Version
2.13.0

Definition at line 656 of file sandbox.cpp.


The documentation for this class was generated from the following files: