Buckets:

download
raw
49.4 kB
<meta charset="utf-8" /><meta name="hf:doc:metadata" content="{&quot;title&quot;:&quot;OpenCode Environment for OpenEnv&quot;,&quot;local&quot;:&quot;opencode-environment-for-openenv&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Quick Start&quot;,&quot;local&quot;:&quot;quick-start&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Async (default — talk to the deployed Space)&quot;,&quot;local&quot;:&quot;async-default--talk-to-the-deployed-space&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Sync wrapper&quot;,&quot;local&quot;:&quot;sync-wrapper&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;In-process primitive (no HTTP)&quot;,&quot;local&quot;:&quot;in-process-primitive-no-http&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3}],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Building the Docker Image&quot;,&quot;local&quot;:&quot;building-the-docker-image&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;The MCP Tool: run_rollout&quot;,&quot;local&quot;:&quot;the-mcp-tool-runrollout&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Two Operating Modes&quot;,&quot;local&quot;:&quot;two-operating-modes&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Environment Variables&quot;,&quot;local&quot;:&quot;environment-variables&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Pre-baked E2B Template&quot;,&quot;local&quot;:&quot;pre-baked-e2b-template&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Project Structure&quot;,&quot;local&quot;:&quot;project-structure&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;References&quot;,&quot;local&quot;:&quot;references&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2}],&quot;depth&quot;:1}"/>
<link href="/docs/openenv/main/en/_app/immutable/entry/start.CdJBJ6Jk.js" rel="modulepreload">
<link href="/docs/openenv/main/en/_app/immutable/chunks/fQO-QNH5.js" rel="modulepreload">
<link href="/docs/openenv/main/en/_app/immutable/chunks/BSuxAqoA.js" rel="modulepreload">
<link href="/docs/openenv/main/en/_app/immutable/entry/app.DMA_b4SN.js" rel="modulepreload">
<link href="/docs/openenv/main/en/_app/immutable/chunks/Ds_1Ru_R.js" rel="modulepreload">
<link href="/docs/openenv/main/en/_app/immutable/chunks/Cnnc8tms.js" rel="modulepreload">
<link href="/docs/openenv/main/en/_app/immutable/chunks/DsnmJJEf.js" rel="modulepreload">
<link href="/docs/openenv/main/en/_app/immutable/chunks/BAUKCucN.js" rel="modulepreload">
<link href="/docs/openenv/main/en/_app/immutable/nodes/0.kbjh0TUT.js" rel="modulepreload">
<link href="/docs/openenv/main/en/_app/immutable/chunks/CR5HsSXT.js" rel="modulepreload">
<link href="/docs/openenv/main/en/_app/immutable/nodes/26.CwBIZFfH.js" rel="modulepreload">
<link href="/docs/openenv/main/en/_app/immutable/chunks/C07d6Hje.js" rel="modulepreload">
<!--hmmsup--><meta name="hf:doc:metadata" content="{&quot;title&quot;:&quot;OpenCode Environment for OpenEnv&quot;,&quot;local&quot;:&quot;opencode-environment-for-openenv&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Quick Start&quot;,&quot;local&quot;:&quot;quick-start&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Async (default — talk to the deployed Space)&quot;,&quot;local&quot;:&quot;async-default--talk-to-the-deployed-space&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Sync wrapper&quot;,&quot;local&quot;:&quot;sync-wrapper&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;In-process primitive (no HTTP)&quot;,&quot;local&quot;:&quot;in-process-primitive-no-http&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3}],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Building the Docker Image&quot;,&quot;local&quot;:&quot;building-the-docker-image&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;The MCP Tool: run_rollout&quot;,&quot;local&quot;:&quot;the-mcp-tool-runrollout&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Two Operating Modes&quot;,&quot;local&quot;:&quot;two-operating-modes&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Environment Variables&quot;,&quot;local&quot;:&quot;environment-variables&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Pre-baked E2B Template&quot;,&quot;local&quot;:&quot;pre-baked-e2b-template&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Project Structure&quot;,&quot;local&quot;:&quot;project-structure&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;References&quot;,&quot;local&quot;:&quot;references&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2}],&quot;depth&quot;:1}"/><!---->
<link href="/docs/openenv/main/en/_app/immutable/assets/0.tn0RQdqM.css" rel="modulepreload"> <!--[--><!--[0--><!--[--><!--[0--><!--[--><p></p> <div class="items-center shrink-0 min-w-[100px] max-sm:min-w-[50px] justify-end ml-auto flex" style="float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"><div class="inline-flex rounded-md max-sm:rounded-sm"><button class="inline-flex items-center gap-1 h-7 max-sm:h-7 px-2 max-sm:px-1.5 text-sm font-medium text-gray-800 border border-r-0 rounded-l-md max-sm:rounded-l-sm border-gray-200 bg-white hover:shadow-inner dark:border-gray-850 dark:bg-gray-950 dark:text-gray-200 dark:hover:bg-gray-800" aria-live="polite"><span class="inline-flex items-center justify-center rounded-md p-0.5 max-sm:p-0 hover:text-gray-800 dark:hover:text-gray-200"><svg class="sm:size-3.5 size-3" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----></span> <span>Copy page</span></button> <button class="inline-flex items-center justify-center w-6 max-sm:w-5 h-7 max-sm:h-7 disabled:pointer-events-none text-sm text-gray-500 hover:text-gray-700 dark:hover:text-white rounded-r-md max-sm:rounded-r-sm border border-l transition border-gray-200 bg-white hover:shadow-inner dark:border-gray-850 dark:bg-gray-950 dark:text-gray-200 dark:hover:bg-gray-800" aria-haspopup="menu" aria-expanded="false" aria-label="Open copy menu"><svg class="transition-transform text-gray-400 overflow-visible sm:size-3.5 size-3 rotate-0" width="1em" height="1em" viewBox="0 0 12 7" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1 1L6 6L11 1" stroke="currentColor"></path></svg><!----></button></div> <!--[-1--><!--]--></div><!----> <!--[0--><h1 class="relative group"><a id="opencode-environment-for-openenv" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#opencode-environment-for-openenv"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>OpenCode Environment for OpenEnv</span></h1><!--]--><!----> <p><code>opencode_env</code> runs the <a href="https://opencode.ai" rel="nofollow">OpenCode</a> coding agent inside
an isolated <a href="https://e2b.dev" rel="nofollow">E2B</a> sandbox against any OpenAI-compatible
LLM endpoint, optionally capturing per-token logprobs for GRPO training.</p> <p><strong>🚀 Try it live</strong>: <a href="https://huggingface.co/spaces/AdithyaSK/opencode-env" rel="nofollow"><code>AdithyaSK/opencode-env</code></a></p> <p>The deployed Space exposes:</p> <ul><li><strong>Web UI</strong> at <a href="https://adithyask-opencode-env.hf.space/web" rel="nofollow"><code>/web</code></a> — pick endpoint, write task, hit Run, watch live phase log + reward + logprobs.</li> <li><strong>MCP tool API</strong> at <a href="https://adithyask-opencode-env.hf.space/mcp" rel="nofollow"><code>/mcp</code></a> — programmatic <code>run_rollout</code> calls.</li> <li><strong>OpenAPI docs</strong> at <a href="https://adithyask-opencode-env.hf.space/docs" rel="nofollow"><code>/docs</code></a>.</li> <li><strong>Health</strong> at <a href="https://adithyask-opencode-env.hf.space/health" rel="nofollow"><code>/health</code></a>.</li></ul> <p>The env is <strong>task-agnostic</strong> — every rollout is configured at call-time
with a uniform Task shape:</p> <ul><li><strong><code>instruction</code></strong> — prompt for the agent</li> <li><strong><code>setup</code></strong> — list of bash commands run <em>before</em> the agent (pip
install, git clone, file downloads — anything you need staged in the
sandbox)</li> <li><strong><code>verify</code></strong> — list of bash commands run <em>after</em> the agent (asserts,
pytest invocations, score-file writes)</li></ul> <p>Reward = <code>passed_verify / total_verify</code> unless any <code>verify</code> command writes
a float to <code>/home/user/logs/verifier/reward.txt</code> (override).</p> <!--[1--><h2 class="relative group"><a id="quick-start" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#quick-start"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>Quick Start</span></h2><!--]--><!----> <!--[2--><h3 class="relative group"><a id="async-default--talk-to-the-deployed-space" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#async-default--talk-to-the-deployed-space"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>Async (default — talk to the deployed Space)</span></h3><!--]--><!----> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copied</div><!----></button><!----></div> <pre class="language-python "><!----><span class="hljs-keyword">import</span> asyncio
<span class="hljs-keyword">import</span> os
<span class="hljs-keyword">from</span> opencode_env <span class="hljs-keyword">import</span> OpenCodeEnv
<span class="hljs-keyword">from</span> opencode_env.client <span class="hljs-keyword">import</span> _extract_text
<span class="hljs-keyword">from</span> opencode_env.models <span class="hljs-keyword">import</span> RolloutResult
<span class="hljs-keyword">async</span> <span class="hljs-keyword">def</span> <span class="hljs-title function_">main</span>():
SPACE = <span class="hljs-string">&quot;https://adithyask-opencode-env.hf.space&quot;</span>
<span class="hljs-keyword">async</span> <span class="hljs-keyword">with</span> OpenCodeEnv(base_url=SPACE) <span class="hljs-keyword">as</span> env:
<span class="hljs-keyword">await</span> env.reset()
<span class="hljs-comment"># The MCP tool returns JSON; deserialize via the typed model.</span>
raw = <span class="hljs-keyword">await</span> env.call_tool(
<span class="hljs-string">&quot;run_rollout&quot;</span>,
endpoint=<span class="hljs-string">&quot;openai&quot;</span>, <span class="hljs-comment"># vllm | openai | hf_router</span>
api_key=os.environ[<span class="hljs-string">&quot;OPENAI_API_KEY&quot;</span>], <span class="hljs-comment"># or set as a Space secret</span>
instruction=(
<span class="hljs-string">&quot;Create binary_search.py exposing def binary_search(arr, target) -&gt; int &quot;</span>
<span class="hljs-string">&quot;that returns the index of target in arr, or -1 if absent. Use a &quot;</span>
<span class="hljs-string">&quot;relative path.&quot;</span>
),
setup=[],
verify=[
<span class="hljs-string">&quot;test -f /home/user/workdir/binary_search.py&quot;</span>,
<span class="hljs-string">&quot;python -c \&quot;import sys; sys.path.insert(0, &#x27;/home/user/workdir&#x27;); &quot;</span>
<span class="hljs-string">&quot;import binary_search; &quot;</span>
<span class="hljs-string">&quot;assert binary_search.binary_search([1,2,3], 2) == 1; print(&#x27;OK&#x27;)\&quot;&quot;</span>,
],
template=<span class="hljs-string">&quot;opencode-rl&quot;</span>, <span class="hljs-comment"># prebaked E2B template</span>
task_id=<span class="hljs-string">&quot;binary_search_v1&quot;</span>,
)
result = RolloutResult.model_validate_json(_extract_text(raw))
<span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;reward:&quot;</span>, result.reward)
<span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;turns:&quot;</span>, <span class="hljs-built_in">len</span>(result.proxy_turns))
<span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;files:&quot;</span>, <span class="hljs-built_in">list</span>(result.files.keys()))
<span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;wall:&quot;</span>, result.wall_s, <span class="hljs-string">&quot;s&quot;</span>)
asyncio.run(main())<!----></pre></div><!----> <p>Expected output (~20s with the prebaked template):</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copied</div><!----></button><!----></div> <pre class=" "><!----><span class="hljs-attribute">reward</span>: <span class="hljs-number">1</span>.<span class="hljs-number">0</span>
<span class="hljs-attribute">turns</span>: <span class="hljs-number">3</span>
<span class="hljs-attribute">files</span>:<span class="hljs-meta"> [&#x27;/home/user/workdir/binary_search.py&#x27;, ...]</span>
<span class="hljs-attribute">wall</span>: <span class="hljs-number">19</span>.<span class="hljs-number">8</span> s<!----></pre></div><!----> <!--[2--><h3 class="relative group"><a id="sync-wrapper" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#sync-wrapper"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>Sync wrapper</span></h3><!--]--><!----> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copied</div><!----></button><!----></div> <pre class="language-python "><!----><span class="hljs-keyword">import</span> os
<span class="hljs-keyword">from</span> opencode_env <span class="hljs-keyword">import</span> OpenCodeEnv
<span class="hljs-comment"># .sync() returns a synchronous wrapper around the async client.</span>
<span class="hljs-keyword">with</span> OpenCodeEnv(base_url=<span class="hljs-string">&quot;https://adithyask-opencode-env.hf.space&quot;</span>).sync() <span class="hljs-keyword">as</span> env:
env.reset()
<span class="hljs-comment"># MCP tools are reachable via env.call_tool(...) / env.step(...) sync-wrapped.</span>
<span class="hljs-comment"># See the async example above for the full run_rollout signature.</span><!----></pre></div><!----> <p>Point <code>base_url</code> at <code>http://localhost:8000</code> to talk to a local container
instead of the public Space.</p> <!--[2--><h3 class="relative group"><a id="in-process-primitive-no-http" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#in-process-primitive-no-http"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>In-process primitive (no HTTP)</span></h3><!--]--><!----> <p>For trainers that want to drive a sandbox directly without an HTTP boundary:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copied</div><!----></button><!----></div> <pre class="language-python "><!----><span class="hljs-keyword">import</span> os
<span class="hljs-keyword">from</span> opencode_env <span class="hljs-keyword">import</span> (
OpenCodeConfig, OpenCodeSessionFactory, OpenCodeTask, E2BSandboxBackend,
)
factory = OpenCodeSessionFactory(
config=OpenCodeConfig(
provider=<span class="hljs-string">&quot;openai_compatible&quot;</span>,
base_url=<span class="hljs-string">&quot;https://api.openai.com/v1&quot;</span>,
api_key=os.environ[<span class="hljs-string">&quot;OPENAI_API_KEY&quot;</span>],
model=<span class="hljs-string">&quot;gpt-4o-mini&quot;</span>,
),
sandbox_backend=E2BSandboxBackend(),
mode=<span class="hljs-string">&quot;transparent_proxy&quot;</span>, <span class="hljs-comment"># captures per-token logprobs</span>
)
session = factory.create(task=OpenCodeTask(instruction=<span class="hljs-string">&quot;...&quot;</span>))
session.wait_for_completion()
turns = session.fetch_proxy_trace() <span class="hljs-comment"># per-turn (tokens, logprobs)</span>
session.close()<!----></pre></div><!----> <!--[1--><h2 class="relative group"><a id="building-the-docker-image" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#building-the-docker-image"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>Building the Docker Image</span></h2><!--]--><!----> <p>The Dockerfile lives at <code>server/Dockerfile</code>. Use the <code>openenv</code> CLI from
the env root:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copied</div><!----></button><!----></div> <pre class="language-bash "><!----><span class="hljs-built_in">cd</span> envs/opencode_env
openenv validate <span class="hljs-comment"># check pyproject.toml + openenv.yaml + server/app.py + uv.lock</span>
openenv build -t opencode-env <span class="hljs-comment"># builds the image (uses server/Dockerfile)</span>
<span class="hljs-comment"># run locally with E2B credentials</span>
docker run -p 8000:8000 -e E2B_API_KEY=e2b_... opencode-env
<span class="hljs-comment"># push to HF Spaces (Docker variant)</span>
openenv push --repo-id &lt;user&gt;/opencode-env<!----></pre></div><!----> <p>Or build directly without the CLI:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copied</div><!----></button><!----></div> <pre class="language-bash "><!---->docker build -t opencode-env -f envs/opencode_env/server/Dockerfile envs/opencode_env<!----></pre></div><!----> <p>The image:</p> <ul><li>Runs <code>uvicorn server.app:app --host 0.0.0.0 --port 8000</code></li> <li>Exposes the MCP API at <code>/mcp</code> and <code>/step</code>, the Gradio UI at <code>/web</code>,
health at <code>/health</code>, and OpenAPI docs at <code>/docs</code>.</li> <li>Reads <code>E2B_API_KEY</code> and (optionally) endpoint-specific env vars at
runtime (see <a href="#environment-variables">Environment Variables</a>).</li></ul> <!--[1--><h2 class="relative group"><a id="the-mcp-tool-runrollout" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#the-mcp-tool-runrollout"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>The MCP Tool: run_rollout</span></h2><!--]--><!----> <p>Single tool, two ways to specify the LLM endpoint:</p> <p><strong>Option A — endpoint shorthand (recommended)</strong>: pass <code>endpoint="vllm"</code> (or <code>"openai"</code> / <code>"hf_router"</code>). The server resolves <code>base_url</code>, <code>api_key</code>, and <code>model</code> from env vars + catalog defaults.
Any explicit field overrides the catalog.</p> <p><strong>Option B — fully explicit</strong>: pass <code>base_url</code> + <code>api_key</code> + <code>model</code> directly.</p> <table><thead><tr><th>Arg</th><th>Type</th><th>Default</th><th>Notes</th></tr></thead><tbody><tr><td><code>endpoint</code></td><td><code>str</code></td><td><code>""</code></td><td>One of <code>"vllm"</code> / <code>"openai"</code> / <code>"hf_router"</code>.</td></tr><tr><td><code>base_url</code> / <code>api_key</code> / <code>model</code></td><td><code>str</code></td><td><code>""</code></td><td>Override / supply explicitly.</td></tr><tr><td><code>instruction</code></td><td><code>str</code></td><td>required</td><td>Prompt passed to <code>opencode run</code>.</td></tr><tr><td><code>setup</code></td><td><code>list[str]</code></td><td><code>[]</code></td><td>Bash commands run <strong>before</strong> the agent.</td></tr><tr><td><code>verify</code></td><td><code>list[str]</code></td><td><code>[]</code></td><td>Bash commands run <strong>after</strong> the agent.</td></tr><tr><td><code>task_id</code></td><td><code>str</code></td><td><code>""</code></td><td>Echoed back in result.</td></tr><tr><td><code>mode</code></td><td><code>str</code></td><td><code>"transparent_proxy"</code></td><td>Or <code>"black_box"</code> (no logprobs).</td></tr><tr><td><code>disable_thinking</code></td><td><code>bool \| None</code></td><td><code>None</code> (catalog default)</td><td>Inject <code>chat_template_kwargs.enable_thinking=false</code>.</td></tr><tr><td><code>max_tokens_cap</code></td><td><code>int</code></td><td><code>4096</code></td><td>Per-turn <code>max_tokens</code> clamp.</td></tr><tr><td><code>top_logprobs</code></td><td><code>int</code></td><td><code>5</code></td><td>HF Router cap is 5; OpenAI 0–20; vLLM unbounded.</td></tr><tr><td><code>agent_timeout_s</code></td><td><code>float</code></td><td><code>600.0</code></td><td>Hard wall budget for opencode.</td></tr><tr><td><code>template</code></td><td><code>str</code></td><td><code>""</code></td><td>E2B template name; <code>"opencode-rl"</code> skips ~2 min of install per rollout.</td></tr></tbody></table> <p>Returns <code>RolloutResult</code> JSON with: <code>reward</code>, <code>setup_results[]</code>, <code>verify_results[]</code>, <code>proxy_turns[]</code>, <code>files{}</code>, <code>agent_log_tail</code>, <code>proxy_log_tail</code>, <code>wall_s</code>, <code>agent_exit_code</code>, <code>sandbox_id</code>, <code>error</code>.</p> <!--[1--><h2 class="relative group"><a id="two-operating-modes" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#two-operating-modes"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>Two Operating Modes</span></h2><!--]--><!----> <table><thead><tr><th>Mode</th><th>What it does</th><th>Best for</th></tr></thead><tbody><tr><td><strong><code>transparent_proxy</code></strong> (default)</td><td>In-sandbox proxy at <code>localhost:7000</code> forwards opencode’s LLM calls to <code>base_url</code>, injects <code>logprobs=true</code>, captures per-turn <code>(messages, completion_tokens, logprobs)</code> to <code>proxy_trace.jsonl</code>.</td><td>GRPO / RL training, observability, top-k distillation.</td></tr><tr><td><strong><code>black_box</code></strong></td><td>No proxy. opencode talks straight to <code>base_url</code>.</td><td>Smoke tests, eval, SFT data collection.</td></tr></tbody></table> <!--[1--><h2 class="relative group"><a id="environment-variables" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#environment-variables"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>Environment Variables</span></h2><!--]--><!----> <p>The server reads these at runtime. Local dev auto-loads them from a
sibling <code>.env</code> file; on HF Spaces, set them as <strong>Space secrets</strong>.</p> <table><thead><tr><th>Variable</th><th>Required</th><th>Purpose</th></tr></thead><tbody><tr><td><code>E2B_API_KEY</code></td><td><strong>yes</strong> for any rollout</td><td>E2B sandbox credentials.</td></tr><tr><td><code>MAX_CONCURRENT_ENVS</code></td><td>no</td><td>Env-instance pool size. Default <code>4</code>.</td></tr><tr><td><code>ENABLE_WEB_INTERFACE</code></td><td>no</td><td>Set <code>false</code> to disable the <code>/web</code> Gradio mount. Default <code>true</code>.</td></tr><tr><td><strong>vLLM endpoint</strong></td><td></td><td></td></tr><tr><td><code>VLLM_URL</code></td><td>required for <code>endpoint="vllm"</code></td><td>OAI-compatible base URL.</td></tr><tr><td><code>VLLM_API_KEY</code></td><td>no</td><td>Defaults to <code>intercepted</code>.</td></tr><tr><td><code>VLLM_MODEL</code></td><td>no</td><td>Defaults to <code>Qwen/Qwen3.5-4B</code>.</td></tr><tr><td><strong>OpenAI endpoint</strong></td><td></td><td></td></tr><tr><td><code>OPENAI_API_KEY</code></td><td>required for <code>endpoint="openai"</code></td><td>Standard OpenAI key.</td></tr><tr><td><code>OPENAI_BASE_URL</code></td><td>no</td><td>Defaults to <code>https://api.openai.com/v1</code>.</td></tr><tr><td><code>OPENAI_MODEL</code></td><td>no</td><td>Defaults to <code>gpt-4o-mini</code> (gpt-5.x and o-series refuse logprobs).</td></tr><tr><td><strong>HF Router endpoint</strong></td><td></td><td></td></tr><tr><td><code>HF_ROUTER_API_KEY</code></td><td>required for <code>endpoint="hf_router"</code></td><td>HF user token.</td></tr><tr><td><code>HF_ROUTER_BASE_URL</code></td><td>no</td><td>Defaults to <code>https://router.huggingface.co/v1</code>.</td></tr><tr><td><code>HF_ROUTER_MODEL</code></td><td>no</td><td>Defaults to <code>Qwen/Qwen3-4B-Instruct-2507:nscale</code>.</td></tr></tbody></table> <p>Pick <code>provider:</code> suffixes that actually return logprobs: <strong>Together / Nscale / Scaleway / SambaNova / Cerebras</strong>. Avoid Novita /
Hyperbolic / Featherless (silent drop) and Groq (HTTP 400).</p> <!--[1--><h2 class="relative group"><a id="pre-baked-e2b-template" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#pre-baked-e2b-template"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>Pre-baked E2B Template</span></h2><!--]--><!----> <p>The first rollout in a fresh E2B sandbox spends ~2 min installing
opencode and the proxy’s Python deps. Build a one-time template that
ships those pre-installed:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copied</div><!----></button><!----></div> <pre class="language-bash "><!---->.venv/bin/python envs/opencode_env/sandbox/build_template.py
<span class="hljs-comment"># → builds `opencode-rl` template in your E2B account (~1m20s, one-time)</span><!----></pre></div><!----> <p>After this, pass <code>template="opencode-rl"</code> on every <code>run_rollout</code> call —
each rollout drops to ~20–30s end-to-end.</p> <!--[1--><h2 class="relative group"><a id="project-structure" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#project-structure"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>Project Structure</span></h2><!--]--><!----> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copied</div><!----></button><!----></div> <pre class=" "><!---->opencode_env<span class="hljs-symbol">/</span>
├── README.md <span class="hljs-comment"># this file</span>
├── openenv.yaml <span class="hljs-comment"># OpenEnv space spec</span>
├── pyproject.toml <span class="hljs-comment"># deps + ``server`` entrypoint</span>
├── uv.lock <span class="hljs-comment"># frozen deps (required by ``openenv validate``)</span>
├── .gitignore <span class="hljs-symbol">/</span> .dockerignore <span class="hljs-comment"># excludes .env / __pycache__</span>
├── __init__.py <span class="hljs-comment"># re-exports primitive + client + models</span>
├── client.py <span class="hljs-comment"># OpenCodeEnv(MCPToolClient)</span>
├── models.py <span class="hljs-comment"># RolloutResult / RolloutTurn / OpenCodeState</span>
├── config.py <span class="hljs-comment"># OpenCodeConfig (primitive)</span>
├── harness.py <span class="hljs-comment"># OpenCodeSession / OpenCodeSessionFactory (CLI-only)</span>
├── opencode_runtime.py <span class="hljs-comment"># opencode.json builder + cmds</span>
├── task.py <span class="hljs-comment"># OpenCodeTask</span>
├── server<span class="hljs-symbol">/</span>
│ ├── __init__.py
│ ├── app.py <span class="hljs-comment"># FastAPI factory; mounts Gradio at /web</span>
│ ├── opencode_environment.py <span class="hljs-comment"># MCPEnvironment with single ``run_rollout`` tool</span>
│ ├── gradio_ui.py <span class="hljs-comment"># the /web Gradio Blocks UI</span>
│ ├── catalog.py <span class="hljs-comment"># endpoint shorthand resolver</span>
│ └── Dockerfile <span class="hljs-comment"># multi-stage uv build (used by ``openenv build``)</span>
└── sandbox<span class="hljs-symbol">/</span>
├── __init__.py
├── base.py <span class="hljs-comment"># SandboxBackend / SandboxHandle Protocols</span>
├── e2b.py <span class="hljs-comment"># E2B implementation</span>
├── interception.py <span class="hljs-comment"># in-sandbox FastAPI proxy (logprob capture)</span>
└── build_template.py <span class="hljs-comment"># one-time E2B template builder</span><!----></pre></div><!----> <!--[1--><h2 class="relative group"><a id="references" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#references"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>References</span></h2><!--]--><!----> <ul><li><a href="https://huggingface.co/docs/openenv" rel="nofollow">OpenEnv docs</a></li> <li><a href="https://opencode.ai/docs/cli/" rel="nofollow">OpenCode CLI</a></li> <li><a href="https://e2b.dev/docs" rel="nofollow">E2B Python SDK</a></li> <li><a href="../../../DOCS/HF/hf_inference_providers_logprobs">HF Inference Providers logprob matrix</a></li></ul> <a class="!text-gray-400 !no-underline text-sm flex items-center not-prose mt-4" href="https://github.com/huggingface/openenv/blob/main/docs/source/environments/opencode.md" target="_blank"><svg class="mr-1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M31,16l-7,7l-1.41-1.41L28.17,16l-5.58-5.59L24,9l7,7z"></path><path d="M1,16l7-7l1.41,1.41L3.83,16l5.58,5.59L8,23l-7-7z"></path><path d="M12.419,25.484L17.639,6.552l1.932,0.518L14.351,26.002z"></path></svg><!----> <span><span class="underline">Update</span> on GitHub</span></a><!----> <p></p><!--]--><!----><!--]--><!--]--><!--]--> <!--[-1--><!--]--><!--]-->
<script>
{
__sveltekit_13d627l = {
base: "/docs/openenv/main/en",
assets: "/docs/openenv/main/en"
};
const element = document.currentScript.parentElement;
Promise.all([
import("/docs/openenv/main/en/_app/immutable/entry/start.CdJBJ6Jk.js"),
import("/docs/openenv/main/en/_app/immutable/entry/app.DMA_b4SN.js")
]).then(([kit, app]) => {
kit.start(app, element, {
node_ids: [0, 26],
data: [null,null],
form: null,
error: null
});
});
}
</script>

Xet Storage Details

Size:
49.4 kB
·
Xet hash:
81c0c1f8b44a69f8e4c7f11816589cd2e02cdbe3cae29e92238410467fd91edf

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.