Skip to content

[bug] Code Execution Fails When Workspace is Not Set to /root #154

@YaoZengzeng

Description

@YaoZengzeng

Summary

Code execution through the picod service does not work correctly when the --workspace argument is set to a directory other than /root (e.g., /workspace). This causes execution failures and unexpected behavior when using the CodeInterpreterClient.

Environment

  • Component: picod (Code Execution Service)
  • Image: ghcr.io/volcano-sh/picod:latest
  • Affected Files:
    • docs/getting-started.md
    • example/code-interpreter/code-interpreter.yaml

Problem Description

When the picod container is started with --workspace=/workspace (or any directory other than /root), code execution requests fail or behave unexpectedly. The issue stems from the fact that the specified workspace directory may not exist or is not properly initialized in the container.

Root Cause

Looking at pkg/picod/execute.go, the command execution logic is:

// Set working directory
if req.WorkingDir != "" {
    safeWorkingDir, err := s.sanitizePath(req.WorkingDir)
    if err != nil {
        c.JSON(http.StatusBadRequest, gin.H{
            "error": fmt.Sprintf("Invalid working directory: %v", err),
            "code":  http.StatusBadRequest,
        })
        return
    }
    cmd.Dir = safeWorkingDir
}

When working_dir is not explicitly provided in the execution request, the command runs in the default working directory of the picod process. However, if the workspace is set to a non-existent directory like /workspace:

  1. The directory may not exist in the container
  2. File operations and command executions fail
  3. Code that relies on writing/reading files cannot function properly

Steps to Reproduce

  1. Deploy picod with workspace set to /workspace:

    args:
      - --workspace=/workspace
  2. Attempt to execute code using the CodeInterpreterClient:

    from agentcube import CodeInterpreterClient
    
    with CodeInterpreterClient(name="my-interpreter") as client:
        result = client.run_code("python", "print('Hello from AgentCube!')")
        print(result)
  3. Observe execution failures or unexpected behavior

Expected Behavior

Code execution should work seamlessly regardless of the configured workspace directory, with the directory being properly created and accessible.

Actual Behavior

Code execution fails when workspace is set to a directory that doesn't exist (e.g., /workspace).

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions