Add dmr sandbox config and launch command#922
Conversation
There was a problem hiding this comment.
Hey - I've found 1 security issue
Security issues:
- Detected non-static command inside Command. Audit the input to 'exec.Command'. If unverified user data can reach this call site, this is a code injection vulnerability. A malicious actor can inject a malicious script to execute arbitrary code. (link)
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="cmd/dmr/main.go" line_range="113" />
<code_context>
cmd := exec.Command(sandboxTool, args...)
</code_context>
<issue_to_address>
**security (go.lang.security.audit.dangerous-exec-command):** Detected non-static command inside Command. Audit the input to 'exec.Command'. If unverified user data can reach this call site, this is a code injection vulnerability. A malicious actor can inject a malicious script to execute arbitrary code.
*Source: opengrep*
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds lightweight dmr config / dmr launch behaviors to the dmr CLI by persisting a sandbox tool in a user config file and executing it via os/exec.
Changes:
- Added early
os.Argsdispatch forconfigandlaunchcommands. - Implemented writing/reading
sandbox.toolin a TOML-like config under the user config dir. - Added a launcher that execs the configured sandbox tool with forwarded stdio.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Code Review
This pull request introduces new config and launch commands to manage a sandbox tool configuration. However, the current implementation contains several critical issues: the manual command handling in run() shadows existing Cobra subcommands, creating a regression; the configuration writing logic is destructive and will overwrite existing file content; and the configuration parser fails to correctly handle escaped characters in quoted strings. The reviewer recommends integrating these features into the existing Cobra command tree and using strconv.Unquote for reliable string parsing.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
| if key != "sandbox.tool" { | ||
| return fmt.Errorf("unsupported config key %q", key) | ||
| } | ||
|
|
There was a problem hiding this comment.
perhaps much better if we can add a list of supported tools in the top of the file and only support here like
var allowedSandboxTools = map[string]struct{}{
"firejail": {},
"bubblewrap": {},
"bwrap": {},
}
if _, ok := allowedSandboxTools[value]; !ok {
return fmt.Errorf("unsupported sandbox tool %q", sandboxTool)
}
There was a problem hiding this comment.
Sure but lets just start with sbx for this PR, these can be follow on PRs
There was a problem hiding this comment.
@ericcurtin yes, this was my exact point, like it's better if we can specify the supported ones, both here and the launch
| if err != nil { | ||
| return err | ||
| } | ||
|
|
There was a problem hiding this comment.
same thing like above can be done here for verifying supported tools
|
@CoderHariswar something i noticed when reviewing is. Is there any reason you didn't use the same pattern in the implementation like registering a subcommand like the |
|
We must ensure this works for model-cli and dmr. And test, test, test to see this works as expected |
|
Thanks for the review @sathiraumesh I was confused at first because My first fix handled I updated the PR to follow that approach:
Tested locally with: go test ./cmd/cli/commands I also manually tested |
We want to do a brand new "config", "git config"-style, using toml, the old "configure" we should deprecate it's kinda strange, it only lives as long as the daemon |
|
Got it @ericcurtin for this PR I focused on |
| Short: "Manage model runtime configurations", | ||
| Hidden: true, | ||
| Use: "configure [--context-size=<n>] [--speculative-draft-model=<model>] [--hf_overrides=<json>] [--gpu-memory-utilization=<float>] [--mode=<mode>] [--think] [--keep-alive=<duration>] MODEL [-- <runtime-flags...>]", | ||
| Short: "Manage model runtime configurations", |
There was a problem hiding this comment.
I was hoping this wouldn't be removed we could keep this like this without removing if not it would break the style of dmr config or docker model config style .
What i suggest is we register it as a sub command in config. so one can do dmr config sandbox.tool ... or docker model config sandbox.tool
like c.AddCommand(newSandboxConfigCmd()) (note that sandbox.tool is not lke a cmd style format but not sure in this case there is any other approach)
| if ca, ok := containerApps[app]; ok { | ||
| return launchContainerApp(cmd, ca, ep.container, image, port, detach, appArgs, dryRun) | ||
| } | ||
|
|
There was a problem hiding this comment.
can remove these line space changes which i think is not part of changes
| } | ||
|
|
||
| func launchSandboxedHostApp(cmd *cobra.Command, sandboxTool, app string, appArgs []string, dryRun bool) error { | ||
| if err := validateSandboxTool(sandboxTool); err != nil { |
There was a problem hiding this comment.
much better if we can retrieve so everything related to the sandbox happens inside the sandbox.go
err, validatedSbxTool = `validateSandboxTool(sandboxTool)
if err != nil {
return err
}
Then remove the switch ... and directly
if dryRun {
cmd.Printf("sbx %s\n", strings.Join(args, " "))
return nil
}
launchCmd := exec.Command("sbx", args...)
launchCmd.Stdin = os.Stdin
launchCmd.Stdout = os.Stdout
launchCmd.Stderr = os.Stderr
return launchCmd.Run()
| } | ||
| } | ||
|
|
||
| func validateSandboxTool(tool string) error { |
There was a problem hiding this comment.
can change as above mentioned suggestions
| newShowCmd(), | ||
| newComposeCmd(), | ||
| newLaunchCmd(), | ||
| newSandboxConfigCmd(), |
There was a problem hiding this comment.
we don't need to do this if we do as a configs sub command
There was a problem hiding this comment.
Should be newConfigCmd, this will be a generic config system, sandbox is just one of the things
|
Probably you might need to check if |
Fixes #915
Describe the changes you have made in this PR -
This PR adds support for configuring and launching tools through a sandbox from the
dmrwrapper.Users can now configure the sandbox tool with:
The above command writes TOML-style config
Manual Testing done using the following commands
Tested launch through a fake sandbox command and outputs have been verified successfully