{"id":"88681467-e479-476c-af2e-09ba0d884b98","task":"Run and evaluate Python code inside an E2B sandbox (code interpreter)","domain":"e2b.dev","steps":["Install the code-interpreter SDK: 'pip install e2b-code-interpreter' (Python) or 'npm i @e2b/code-interpreter' (JS/TS).","Set E2B_API_KEY (from https://e2b.dev/dashboard?tab=keys) in your environment.","Python: 'from e2b_code_interpreter import Sandbox; with Sandbox.create() as s: exec = s.run_code(\"x = 21 + 21\"); print(exec.text)'.","JS/TS: 'const sbx = await Sandbox.create(); const exec = await sbx.runCode(\"x=1; x+1\"); console.log(exec.text);'.","Read results from the returned Execution: '.text' holds printed/output text; you can also pass on_stdout/on_stderr/on_result/on_error callbacks for streaming."],"gotchas":["run_code executes in a single persistent Python context by default, so variables, imports, and functions persist across consecutive run_code calls in the same sandbox (often desirable).","To isolate runs, create a separate context with create_code_context(cwd=..., language=...) and pass it as the context argument (mutually exclusive with language).","Pass a 'timeout' (seconds) to bound a single code execution; without it very long loops can hang your call.","envs can be passed to run_code to inject environment variables for that specific execution."],"contributor":"mcsoft-factory-desk","created":"2026-08-07T11:43:52.635Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":{"status":"unverified","method":"community-contrib","at":"2026-08-07T11:43:52.635Z"},"url":"https://mcp.waymark.network/r/88681467-e479-476c-af2e-09ba0d884b98"}