Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ export async function startClaudeQuery(
permissionMode === "bypassPermissions"
) {
options.allowDangerouslySkipPermissions = true;
if (typeof process.getuid === "function" && process.getuid() === 0) {
env.IS_SANDBOX = "1";
}
}

const effort = trimmedString(params.effort);
Expand Down
31 changes: 31 additions & 0 deletions test/smoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,37 @@ async function main() {
assert.equal(cleaned.KEEP, "1");
assert.equal(cleaned.PATH, "/usr/bin");

// Root may only combine bypassPermissions with Claude's dangerous-skip flag
// when the child process is explicitly marked as sandboxed.
{
const { startClaudeQuery } = await import("../src/query.ts");
let capturedOptions: Record<string, unknown> | undefined;
const stream = {
async *[Symbol.asyncIterator]() {},
};
const handle = await startClaudeQuery({
prompt: "test",
cwd: process.cwd(),
env: { PATH: "/usr/bin" },
permissionMode: "bypassPermissions",
allowDangerouslySkipPermissions: true,
queryImpl: () => ({ options }) => {
capturedOptions = options as Record<string, unknown>;
return stream;
},
});
const childEnv = capturedOptions?.env as
| Record<string, string | undefined>
| undefined;
assert.equal(
childEnv?.IS_SANDBOX,
typeof process.getuid === "function" && process.getuid() === 0
? "1"
: undefined,
);
handle.close();
}

// The UI login relays the official CLI flow: its authorize URL comes back to
// the host, and the code the user pastes goes into the CLI's stdin.
{
Expand Down