code-interpreter icon indicating copy to clipboard operation
code-interpreter copied to clipboard

run_code as a user instead of root

Open mishushakov opened this issue 8 months ago • 4 comments

  • Jupyter Server and Code Interpreter are started as a non-privileged user
  • Adds ability to change user by creating a new context
  • BREAKING: Default user root > user to match the Sandbox commands.run behavior
  • POSSIBLY BREAKING: when cwd is not set and user is root, it will set cwd to /root

Sample code

const ctx = await sbx.createCodeContext({ language: "python", user: "user" })

const code = await sbx.runCode(`import getpass; print(getpass.getuser())`, { context })
console.log(code.logs);
{
    stdout: [ "user\n" ],
    stderr: [],
}

mishushakov avatar Apr 28 '25 11:04 mishushakov

This won't be probably backwards compatible right?

Can I specify if I want run something as root?

jakubno avatar Apr 28 '25 12:04 jakubno

Not backwards-compatible. You cannot specify the user, the kernels start as same user as Jupyter. There is a possible some workaround suggested by ChatGPT but it's a bit inconvenient:

Screenshot 2025-04-28 at 14 32 17

mishushakov avatar Apr 28 '25 12:04 mishushakov

I created a new template, code-interpreter-v1beta1

mishushakov avatar May 14 '25 19:05 mishushakov