Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
cf2761b
feat(deepagents-code): add dcode status and allow OpenShell TLS key i…
laitingsheng Jul 2, 2026
85588c9
fix(onboard): derive dcode sandbox name from create args
laitingsheng Jul 2, 2026
5bcdfd2
Merge remote-tracking branch 'origin/main' into fix/dcode-status-and-…
laitingsheng Jul 2, 2026
0bfdb01
merge: sync fix/dcode-status-and-infra-key-allowlist with main
prekshivyas Jul 2, 2026
96aa3c4
fix(deepagents-code): add Provider field to dcode status and tighten …
prekshivyas Jul 2, 2026
313ccfc
fix(deepagents-code): add tvly- prefix to secret-shape detection patt…
prekshivyas Jul 2, 2026
a60c2d8
fix(deepagents-code): narrow OpenShell TLS key allowance
apurvvkumaria Jul 2, 2026
467f150
fix(deepagents-code): address status review follow-ups
apurvvkumaria Jul 2, 2026
f25bac9
refactor(onboard): keep entrypoint growth neutral
apurvvkumaria Jul 2, 2026
e54e9ba
test(deepagents-code): extract start script fixture
apurvvkumaria Jul 2, 2026
b0494d9
fix(deepagents-code): complete managed identity status
apurvvkumaria Jul 2, 2026
ea57fdc
fix(deepagents-code): harden identity metadata
apurvvkumaria Jul 2, 2026
7b9891e
fix(dcode): harden identity display metadata
apurvvkumaria Jul 2, 2026
4aaaef6
fix(dcode): redact unsafe status endpoints
apurvvkumaria Jul 2, 2026
4f3f72b
fix(dcode): suppress secret-shaped status metadata
apurvvkumaria Jul 2, 2026
97246a0
fix(dcode): align context secret detection
apurvvkumaria Jul 2, 2026
4d52e7a
merge: sync main into PR 6202
apurvvkumaria Jul 2, 2026
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
57 changes: 55 additions & 2 deletions agents/langchain-deepagents-code/dcode-wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export DEEPAGENTS_CODE_OPENAI_API_KEY="${DEEPAGENTS_CODE_OPENAI_API_KEY:-nemocla
export OPENAI_BASE_URL="${OPENAI_BASE_URL:-https://inference.local/v1}"

readonly DEEPAGENTS_ENV_FILE="/sandbox/.deepagents/.env"
readonly DEEPAGENTS_CONFIG_FILE="/sandbox/.deepagents/config.toml"

run_dcode() {
exec python3 -m deepagents_code "$@"
Expand Down Expand Up @@ -194,6 +195,22 @@ has_credential_name_context() {
return 1
}

# SECURITY: OpenShell injects transport-layer infrastructure variables (such as
# the sandbox's local TLS listener key) into the runtime environment. Their names
# end in a credential keyword, so the name-context heuristic above would refuse to
# start on them even though they are not user provider secrets. Exempt these exact
# names from the name-context rejection ONLY; is_secret_shaped_value still runs on
# every value, so a real provider token carried under one of these names is still
# rejected. Keep this list narrow and exact — never a prefix wildcard.
is_openshell_infra_key_name() {
case "$1" in
OPENSHELL_TLS_KEY)
return 0
;;
esac
return 1
}

is_dynamic_dotenv_value() {
local value="$1"
case "$value" in
Expand Down Expand Up @@ -232,7 +249,7 @@ assert_no_secret_runtime_env() {
if is_secret_shaped_value "$value"; then
refuse_secret_env "runtime environment variable" "$name"
fi
if has_credential_name_context "$name" && [ ${#value} -ge 10 ]; then
if has_credential_name_context "$name" && [ ${#value} -ge 10 ] && ! is_openshell_infra_key_name "$name"; then
refuse_secret_env "runtime environment variable" "$name"
fi
done < <(env -0)
Expand Down Expand Up @@ -282,7 +299,7 @@ assert_no_secret_env_file() {
if is_secret_shaped_value "$value"; then
refuse_secret_env "$env_file" "$key"
fi
if has_credential_name_context "$key" && [ ${#value} -ge 10 ]; then
if has_credential_name_context "$key" && [ ${#value} -ge 10 ] && ! is_openshell_infra_key_name "$key"; then
refuse_secret_env "$env_file" "$key"
fi
done
Expand All @@ -291,7 +308,43 @@ assert_no_secret_env_file() {
assert_no_secret_runtime_env
assert_no_secret_env_file

toml_scalar() {
local key="$1" line
[ -r "$DEEPAGENTS_CONFIG_FILE" ] || return 0
while IFS= read -r line || [ -n "$line" ]; do
case "$line" in
"$key = \""*)
line="${line#"$key = \""}"
printf '%s' "${line%\"}"
return 0
;;
esac
done <"$DEEPAGENTS_CONFIG_FILE"
return 0
}

print_identity() {
local sandbox_name model endpoint
sandbox_name="${NEMOCLAW_SANDBOX_NAME:-unknown}"
model="$(toml_scalar default)"
endpoint="$(toml_scalar base_url)"
[ -n "$endpoint" ] || endpoint="${OPENAI_BASE_URL:-}"
printf 'Sandbox: %s\n' "$sandbox_name"
printf 'Agent: %s\n' 'langchain-deepagents-code'
if [ -n "$model" ]; then
printf 'Model: %s\n' "$model"
fi
if [ -n "$endpoint" ]; then
printf 'Endpoint: %s\n' "$endpoint"
fi
printf 'Runtime: %s\n' 'Deep Agents Code (terminal)'
}

case "${1:-}" in
status | whoami | identity)
print_identity
exit 0
;;
--version | -v | -V | --help | -h)
run_dcode "$@"
;;
Expand Down
1 change: 1 addition & 0 deletions agents/langchain-deepagents-code/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ prepare_runtime_env() {
write_export_if_set LANGSMITH_TRACING
write_export_if_set LANGSMITH_PROJECT
write_export_if_set DEEPAGENTS_CODE_LANGSMITH_PROJECT
write_export_if_set NEMOCLAW_SANDBOX_NAME
} >"$tmp"
chmod 400 "$tmp"
mv -f "$tmp" "$target"
Expand Down
10 changes: 10 additions & 0 deletions docs/get-started/quickstart-langchain-deepagents-code.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ dcode -n "Summarize this repository"

The managed wrapper launches Deep Agents Code with `HOME=/sandbox`, update checks disabled, remote Deep Agents sandbox providers disabled, MCP auto-loading disabled, and shell allow-list overrides blocked.

To confirm which sandbox a session is in, run the identity command:

```bash
dcode status
```

It prints the sandbox name, agent, configured model, and inference endpoint, then exits without starting the interactive UI.
`dcode whoami` and `dcode identity` are aliases.
The sandbox name resolves when you run the command from a `nemoclaw <sandbox-name> connect` shell, which loads the NemoClaw runtime environment.

## Python Environment

Deep Agents Code runs from a NemoClaw-managed Python virtual environment at `/opt/venv`.
Expand Down
1 change: 1 addition & 0 deletions src/lib/onboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3031,6 +3031,7 @@ async function createSandbox(
hermesDashboardState,
manageDashboard,
openshellShellCommand,
sandboxName,
});
const dockerGpuCreatePatch = dockerGpuSandboxCreate.createDockerGpuSandboxCreatePatch({
enabled: useDockerGpuPatch,
Expand Down
35 changes: 35 additions & 0 deletions src/lib/onboard/sandbox-create-launch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,39 @@ describe("prepareSandboxCreateLaunch", () => {
fs.rmSync(tmpDir, { recursive: true, force: true });
}
});

it("forwards the sandbox name into the Deep Agents Code sandbox create env", () => {
const result = prepareSandboxCreateLaunch({
agent: { name: "langchain-deepagents-code" } as any,
chatUiUrl: "",
createArgs: ["--name", "dcode-demo"],
env: {},
extraPlaceholderKeys: [],
getDashboardForwardPort: vi.fn(() => "0"),
hermesDashboardState: disabledHermesDashboardState,
manageDashboard: false,
openshellShellCommand: (args) => args.join(" "),
sandboxName: "dcode-demo",
buildEnv: () => ({}),
});

expect(result.envArgs).toContain("NEMOCLAW_SANDBOX_NAME=dcode-demo");
});

it("does not forward the sandbox name for non-Deep-Agents-Code agents", () => {
const result = prepareSandboxCreateLaunch({
agent: { name: "openclaw", configPaths: { dir: "/sandbox/.custom-openclaw" } } as any,
chatUiUrl: "http://127.0.0.1:19000/",
createArgs: ["--name", "demo"],
env: {},
extraPlaceholderKeys: [],
getDashboardForwardPort: () => "19000",
hermesDashboardState: disabledHermesDashboardState,
openshellShellCommand: (args) => args.join(" "),
sandboxName: "demo",
buildEnv: () => ({}),
});

expect(result.envArgs.some((arg) => arg.startsWith("NEMOCLAW_SANDBOX_NAME="))).toBe(false);
});
});
5 changes: 5 additions & 0 deletions src/lib/onboard/sandbox-create-launch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface SandboxCreateLaunchInput {
hermesDashboardState: HermesDashboardOnboardState;
manageDashboard?: boolean;
openshellShellCommand: OpenshellShellCommand;
sandboxName?: string;
buildEnv?(): Record<string, string>;
}

Expand Down Expand Up @@ -77,6 +78,10 @@ export function prepareSandboxCreateLaunch(input: SandboxCreateLaunchInput): San
envArgs.push(formatEnvAssignment("NEMOCLAW_PROXY_PORT", sandboxProxyPort));
}

if (input.agent?.name === "langchain-deepagents-code" && input.sandboxName) {
envArgs.push(formatEnvAssignment("NEMOCLAW_SANDBOX_NAME", input.sandboxName));
}

appendExtraPlaceholderKeysEnvArg(envArgs, input.extraPlaceholderKeys, formatEnvAssignment);

const sandboxEnv = (input.buildEnv ?? buildSubprocessEnv)();
Expand Down
172 changes: 172 additions & 0 deletions test/dcode-wrapper-identity.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

import { spawnSync } from "node:child_process";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";

import { describe, expect, it } from "vitest";

const WRAPPER = path.join(
import.meta.dirname,
"..",
"agents",
"langchain-deepagents-code",
"dcode-wrapper.sh",
);

const canRun = process.platform === "linux";

const SAMPLE_CONFIG = [
"# Generated by NemoClaw. This file contains no provider secrets.",
"",
"[models]",
'default = "openai:demo-model"',
"",
"[models.providers.openai]",
'models = ["demo-model"]',
'base_url = "https://inference.local/v1"',
"enabled = true",
"",
].join("\n");

const OPAQUE = "Zx3Qw9Lp7Rt2Vn5Bd8Kf1Mh6Cg4Js0Ay";

type Fixture = { wrapperPath: string; ranMarker: string };

function buildFixture(tempDir: string, configContent: string): Fixture {
const wrapperPath = path.join(tempDir, "dcode");
const ranMarker = path.join(tempDir, "dcode-ran");
const envFile = path.join(tempDir, ".env");
const configFile = path.join(tempDir, "config.toml");
const fixture = fs
.readFileSync(WRAPPER, "utf8")
.replace(
'readonly DEEPAGENTS_ENV_FILE="/sandbox/.deepagents/.env"',
`readonly DEEPAGENTS_ENV_FILE="${envFile}"`,
)
.replace(
'readonly DEEPAGENTS_CONFIG_FILE="/sandbox/.deepagents/config.toml"',
`readonly DEEPAGENTS_CONFIG_FILE="${configFile}"`,
)
.replace(
"exec python3 -m deepagents_code",
`touch "${ranMarker}"; echo dcode-stub-ran; exit 0; : python3 -m deepagents_code`,
);
fs.writeFileSync(envFile, "", "utf8");
fs.writeFileSync(configFile, configContent, "utf8");
fs.writeFileSync(wrapperPath, fixture, "utf8");
fs.chmodSync(wrapperPath, 0o755);
return { wrapperPath, ranMarker };
}

type Run = { status: number | null; stdout: string; stderr: string; launched: boolean };

function runWrapper(fixture: Fixture, args: readonly string[], env: NodeJS.ProcessEnv): Run {
const result = spawnSync("bash", [fixture.wrapperPath, ...args], {
env: {
PATH: process.env.PATH ?? "/usr/bin:/bin",
HOME: path.dirname(fixture.wrapperPath),
...env,
},
encoding: "utf8",
timeout: 10000,
});
return {
status: result.status,
stdout: result.stdout ?? "",
stderr: result.stderr ?? "",
launched: fs.existsSync(fixture.ranMarker),
};
}

function withTempDir(run: (dir: string) => void): void {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-dcode-identity-"));
try {
run(dir);
} finally {
fs.rmSync(dir, { recursive: true, force: true });
}
}

describe.skipIf(!canRun)(
"agents/langchain-deepagents-code/dcode-wrapper.sh identity command",
() => {
for (const sub of ["status", "whoami", "identity"]) {
it(`'${sub}' reports the sandbox identity and does not launch dcode`, () => {
withTempDir((dir) => {
const run = runWrapper(buildFixture(dir, SAMPLE_CONFIG), [sub], {
NEMOCLAW_SANDBOX_NAME: "dcode-demo",
});

expect(run.status).toBe(0);
expect(run.launched).toBe(false);
expect(run.stdout).toContain("Sandbox: dcode-demo");
expect(run.stdout).toContain("Agent: langchain-deepagents-code");
expect(run.stdout).toContain("Model: openai:demo-model");
expect(run.stdout).toContain("Endpoint: https://inference.local/v1");
expect(run.stdout).toContain("Runtime: Deep Agents Code (terminal)");
});
});
}

it("reports the sandbox as unknown when the name was not injected", () => {
withTempDir((dir) => {
const run = runWrapper(buildFixture(dir, SAMPLE_CONFIG), ["status"], {});

expect(run.status).toBe(0);
expect(run.launched).toBe(false);
expect(run.stdout).toContain("Sandbox: unknown");
});
});

it("still launches dcode for a normal interactive invocation", () => {
withTempDir((dir) => {
const run = runWrapper(buildFixture(dir, SAMPLE_CONFIG), [], {
NEMOCLAW_SANDBOX_NAME: "dcode-demo",
});

expect(run.status).toBe(0);
expect(run.launched).toBe(true);
});
});
},
);

describe.skipIf(!canRun)(
"agents/langchain-deepagents-code/dcode-wrapper.sh OpenShell infra-key allowlist",
() => {
it("starts dcode when OPENSHELL_TLS_KEY carries an opaque infrastructure value", () => {
withTempDir((dir) => {
const run = runWrapper(buildFixture(dir, SAMPLE_CONFIG), [], { OPENSHELL_TLS_KEY: OPAQUE });

expect(run.status).toBe(0);
expect(run.launched).toBe(true);
expect(run.stderr).not.toContain("refusing to start");
});
});

it("still refuses when OPENSHELL_TLS_KEY carries a real provider token", () => {
withTempDir((dir) => {
const run = runWrapper(buildFixture(dir, SAMPLE_CONFIG), [], {
OPENSHELL_TLS_KEY: `nvapi-${OPAQUE}`,
});

expect(run.status).toBe(2);
expect(run.launched).toBe(false);
expect(run.stderr).toContain("OPENSHELL_TLS_KEY");
});
});

it("still refuses an opaque credential-name-context variable outside the allowlist", () => {
withTempDir((dir) => {
const run = runWrapper(buildFixture(dir, SAMPLE_CONFIG), [], { CUSTOM_API_KEY: OPAQUE });

expect(run.status).toBe(2);
expect(run.launched).toBe(false);
expect(run.stderr).toContain("CUSTOM_API_KEY");
});
});
},
);
19 changes: 19 additions & 0 deletions test/langchain-deepagents-code-image.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,25 @@ describe("LangChain Deep Agents Code image contracts", () => {
expect(envFileText).toContain("export https_proxy=https://safe-proxy.example:8443");
});

it("serializes the sandbox name into the shell env file for in-sandbox identity", () => {
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-dcode-start-"));
try {
const { envFile, scriptPath } = makeStartScriptFixture(tempDir);

execFileSync("bash", [scriptPath, "sh", "-c", ":"], {
env: {
PATH: process.env.PATH ?? "/usr/bin:/bin",
NEMOCLAW_SANDBOX_NAME: "dcode-demo",
},
encoding: "utf8",
});

expect(fs.readFileSync(envFile, "utf8")).toContain("export NEMOCLAW_SANDBOX_NAME=dcode-demo");
} finally {
fs.rmSync(tempDir, { recursive: true, force: true });
}
});

it("omits and unsets credential-bearing proxy URLs", () => {
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-dcode-start-"));
const { envFile, scriptPath } = makeStartScriptFixture(tempDir);
Expand Down
Loading