Optional sandbox for bash, LSP servers and lens/test runners (bwrap, seatbelt)
This commit is contained in:
1 parent
d3390a823d
commit
8e7c0bb89a
11 files changed
+586
-17
No files matched your search
@@ -14,6 +14,17 @@
|
||||
# codemode = false # `codemode` tool: JS scripts that call other tools in a sandbox
|
||||
# system_prompt = "..." # replaces the built-in prompt; AGENTS.md is still appended
|
||||
|
||||
## Sandbox: bash, LSP servers, lens and test runners run under bwrap (Linux) / sandbox-exec (macOS).
|
||||
## Project dir + /tmp writable, $HOME hidden except `ro`/`rw`, filtered env (no API keys/tokens), no network.
|
||||
## File tools (read/write/edit) obey the same paths. mode = "on" without a working backend refuses to start.
|
||||
# [sandbox]
|
||||
# mode = "off" # off | on (CLI: --sandbox / --no-sandbox)
|
||||
# backend = "auto" # auto | bwrap | seatbelt
|
||||
# network = false
|
||||
# rw = ["~/.cargo/registry", "~/.cargo/git"] # extra writable paths
|
||||
# ro = ["~/.cargo", "~/.rustup", "~/.local", "~/.nvm", "~/.npm"] # readable parts of $HOME
|
||||
# env_allow = ["PATH", "HOME", "TERM", "LC_*", "CARGO_*"] # trailing * = prefix
|
||||
|
||||
## OpenAI-compatible endpoint (Ollama, vLLM, LM Studio, OpenRouter), used with provider = "custom".
|
||||
# [openai_compat]
|
||||
# base_url = "http://localhost:11434/v1"
|
||||
|
||||
@@ -39,6 +39,12 @@ struct Cli {
|
||||
/// Skip permission prompts for bash/write/edit (also `permissions = "yolo"` in config.toml).
|
||||
#[arg(long)]
|
||||
yolo: bool,
|
||||
/// Run bash, LSP servers and lens runners in a sandbox (bwrap / seatbelt).
|
||||
#[arg(long, conflicts_with = "no_sandbox")]
|
||||
sandbox: bool,
|
||||
/// Force the sandbox off (overrides config).
|
||||
#[arg(long)]
|
||||
no_sandbox: bool,
|
||||
/// Output mode: text (default for -p), json (NDJSON events on stdout; needs -p), rpc (JSON-RPC on stdio).
|
||||
#[arg(long, value_enum, default_value_t = Mode::Text)]
|
||||
mode: Mode,
|
||||
@@ -129,6 +135,8 @@ struct Config {
|
||||
permissions: Option<String>,
|
||||
/// Replaces the built-in system prompt (AGENTS.md etc. are still appended).
|
||||
system_prompt: Option<String>,
|
||||
/// confine child processes: mode = "on", backend, network, rw, ro, env_allow
|
||||
sandbox: Option<hx_core::sandbox::Cfg>,
|
||||
lsp: Option<LspCfg>,
|
||||
/// subprocess extensions (JSON-RPC over stdio); global and project lists are concatenated
|
||||
extensions: Vec<hx_core::ext::ExtCfg>,
|
||||
@@ -177,6 +185,7 @@ impl Config {
|
||||
remember_model: o.remember_model.or(c.remember_model),
|
||||
permissions: o.permissions.or(c.permissions),
|
||||
system_prompt: o.system_prompt.or(c.system_prompt),
|
||||
sandbox: o.sandbox.or(c.sandbox),
|
||||
lsp: o.lsp.or(c.lsp),
|
||||
extensions: [c.extensions, o.extensions].concat(),
|
||||
};
|
||||
@@ -574,6 +583,14 @@ async fn main() -> Result<()> {
|
||||
let cwd = std::env::current_dir()?;
|
||||
let cfg = Config::load(&cwd)?;
|
||||
trace("config");
|
||||
let mut sb = cfg.sandbox.clone().unwrap_or_default();
|
||||
if cli.sandbox {
|
||||
sb.mode = hx_core::sandbox::Mode::On;
|
||||
}
|
||||
if cli.no_sandbox {
|
||||
sb.mode = hx_core::sandbox::Mode::Off;
|
||||
}
|
||||
hx_core::sandbox::init(&sb, &cwd).map_err(anyhow::Error::msg)?;
|
||||
if let Some(oc) = cfg.openai_compat.clone() {
|
||||
let _ = COMPAT.set(oc);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user